package avicit.cbb.tabledefine.service.impl;

import avicit.cbb.billdefine.service.BillDefineManagerIntfsService;
import avicit.cbb.fondsmanage.service.CbbFondsDbIntfsService;
import avicit.cbb.tabledefine.service.CommTableManagerIntfsService;
import avicit.cbb.techclass.billdefine.action.service.BillDefineManagerService;
import avicit.cbb.techclass.billdefine.service.BillDefineManagerService;
import avicit.cbb.techclass.tabledefine.cbbtabcolcodetl.dto.CbbTabColCodeTlDTO;
import avicit.cbb.techclass.tabledefine.cbbtabcolcodetl.service.CbbTabColCodeTlService;
import avicit.cbb.techclass.tabledefine.cbbtabcolumnstl.dto.CbbTabColumnsTlDTO;
import avicit.cbb.techclass.tabledefine.cbbtabcolumnstl.service.CbbTabColumnsTlService;
import avicit.cbb.techclass.tabledefine.cbbtempletcodetl.service.CbbTempletCodeTlService;
import avicit.cbb.techclass.tabledefine.cbbtempletfieldtl.service.CbbTempletFieldTlService;
import avicit.cbb.techclass.tabledefine.commtablemanager.dao.CommTableManagerDao;
import avicit.cbb.techclass.tabledefine.commtablemanager.domain.*;
import avicit.cbb.techclass.tabledefine.commtablemanager.action.service.CommTableManagerService;
import avicit.im.lantop.basic.archiveclassmanager.action.service.BillDefineManagerIntfsService;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.commons.utils.Pinyin4jUtil;
import avicit.platform6.commons.utils.PojoUtil;
import avicit.platform6.core.dao.hibernate.CommonHibernateDao2;
import avicit.platform6.core.exception.DaoException;
import avicit.platform6.core.jdbc.JdbcAvicit;
import avicit.platform6.core.jdbc.Page;
import avicit.platform6.core.properties.PlatformConstant.OpResult;
import avicit.platform6.core.properties.PlatformConstant.OpType;
import avicit.platform6.core.rest.client.RestClient;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.rest.msg.ResponseStatus;
import avicit.platform6.modules.system.syslog.service.LogBaseFactory;
import avicit.platform6.modules.system.syslog.service.SysLogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.ws.rs.core.GenericType;
import java.math.BigDecimal;
import java.util.*;

/**
 * <p>
 * 金航数码科技有限责任公司
 * </p>
 * <p>
 * 作者：朱锋
 * </p>
 * <p>
 * 邮箱：zhufeng@avicit.com
 * </p>
 * <p>
 * 创建时间： 2014-9-23 下午2:58:29
 * </p>
 * <p>
 * 类说明：库表自定义模块实现类
 * </p>
 * <p>
 * 修改记录：
 * </p>
 */
@SuppressWarnings("unchecked")
@Service
public class CommTableManagerIntfsServiceImpl implements CommTableManagerIntfsService {

	@Autowired
	private CommonHibernateDao2 hibernateDao;
	@Autowired(required = false)
	private JdbcAvicit jdbcAvicit;
	@Autowired(required = true)
	CommTableManagerDao commTableManagerDao;
	@Autowired(required = true)
	BillDefineManagerIntfsService billDefineManagerIntfsService;
	@Autowired(required = true)
	CommTableManagerService commTableManagerService;
	@Autowired(required = true)
	BillDefineManagerService billDefineManagerService;
	// 多语言信息需要调用的service
	@Autowired(required = true)
	CbbTabColumnsTlService cbbTabColumnsTlService;
	@Autowired(required = true)
	CbbTabColCodeTlService cbbTabColCodeTlService;
	@Autowired(required = true)
	CbbTempletFieldTlService cbbTempletFieldTlService;
	@Autowired(required = true)
	CbbTempletCodeTlService cbbTempletCodeTlService;
	@Autowired(required = false)
	CbbFondsDbIntfsService cbbFondsDbIntfsService;


	/**
	 * 节点著录定义添加字段信息
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param tableId
	 * @param colId
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void addCbbTabNodeRecordFieldByIntfs(String orgId, String deptId, String sysId, String nodeId, String tableId, String colId) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.COL_IS_VISIBLE, T.COL_IS_TAB_VISIBLE, T.COL_IS_DETAIL\n");
		sbSql.append("  FROM CBB_TAB_COLUMNS T\n");
		sbSql.append(" WHERE T.ID = '" + colId + "'");
		List<Object[]> objList = hibernateDao.findBySQL(sbSql.toString());
		Object[] obj = objList.get(0);
		CbbTabNodeRecord cbbTabNodeRecord = new CbbTabNodeRecord();
		String id = ComUtil.getId();
		cbbTabNodeRecord.setId(id);
		cbbTabNodeRecord.setTabNodeId(nodeId);
		cbbTabNodeRecord.setColumnId(colId);
		cbbTabNodeRecord.setColIsVisible(String.valueOf(obj[0]));
		cbbTabNodeRecord.setColIsTabVisible(String.valueOf(obj[1]));
		cbbTabNodeRecord.setColIsDetail(String.valueOf(obj[2]));
		cbbTabNodeRecord.setOrgId(orgId);
		cbbTabNodeRecord.setDeptId(deptId);
		cbbTabNodeRecord.setSysId(sysId.toUpperCase());
		PojoUtil.setSysProperties(cbbTabNodeRecord, OpType.insert);
		hibernateDao.save(cbbTabNodeRecord);
		SysLogUtil.log(cbbTabNodeRecord, null, OpType.insert, OpResult.success);
	}

	/**
	 * 根据字段ID获取字段配置信息
	 * @author 郭亮
	 * @param colId
	 * @return
	 * @throws Exception List<String[]>
	 */
	public List<Object[]> getColumnConfigBySourceColId(String colId) throws Exception {
		List<Object[]> configList = new ArrayList<Object[]>();
		String sql = "SELECT T.TARGET_TABLE_ID, T.TARGET_COLUMN_ID, T.TARGET_INPUT, T.TARGET_COLUMN_OPERATION FROM CBB_TAB_COL_CONFIG_GROUP T WHERE T.SOURCE_COLUMN_ID = '" + colId + "' ORDER BY T.GROUP_ORDER";
		configList = this.hibernateDao.findBySQL(sql);
		return configList;
	}

	/**
	 * 拷贝库表
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param oldNodeId
	 * @param newNodeId
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void copyCbbTableByNodeIdByIntfs(String orgId, String deptId, String sysId, String oldNodeId, String newNodeId, String loginUserId, String loginIp, boolean ifTrue) throws Exception {
		sysId = sysId.toUpperCase();
		List<Map<String, Object>> listTab = this.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, oldNodeId, "");// 获取oldTableId
		Map<String, String> tableIdMap = new HashMap<String, String>(); // 表ID集合，格式：<oldTableId, newTableId>，用于更新配置信息取值
		Map<String, String> columnIdMap = new HashMap<String, String>();// 字段ID集合，格式<oldColumnId, newColumnId>，用于更新配置信息取值
		for (int j = 0; j < listTab.size(); j++) {
			String oldTableId = String.valueOf(listTab.get(j).get("ID"));// 旧表ID
			CbbTables cbbTables = getCbbTablesById(oldTableId);// old CbbTables
			// 对象
			String newId = ComUtil.getId();// newTableId
			tableIdMap.put(oldTableId, newId);
			// 1.复制CbbTables记录
			String tableName = cbbTables.getTableName();
			int index = tableName.lastIndexOf("_");
			String fixq = tableName.substring(0, index);// 前缀
			String fixh = tableName.substring(index + 1);// 后缀
			tableName = fixq + "_%_" + fixh;
			int numt = getSumTableCount(tableName);
			tableName = fixq + "_" + numt + "_" + fixh;
			while (true) {
				// 判断数据库是否存在此表
				String hastabSql = "SELECT COUNT(*) FROM ALL_TABLES W WHERE W.TABLE_NAME = '" + tableName + "'";
				List<Object> hastabList = this.hibernateDao.findBySQL(hastabSql);
				if (String.valueOf(hastabList.get(0)).equals("0")) {
					break;
				} else {
					numt++;
				}
			}
			tableName = fixq + "_" + (numt + 1) + "_" + fixh;
			String isTrueTable = "";
			if (ifTrue) {
				isTrueTable = "Y";
			} else {
				isTrueTable = "N";
			}
			insertCbbTables(newId, tableName, cbbTables.getTableTitle() + "_拷贝", orgId, deptId, sysId, loginUserId, loginIp, isTrueTable);
			List<Object> list = getColumnsIdByTableId(oldTableId);
			// 添加列数据
			for (int i = 0; i < list.size(); i++) {
				// 复制 CbbTabColumns 记录
				String cId = String.valueOf(list.get(i));// oldTableColId
				CbbTabColumns cbbTabColumns = getCbbTabColumnsById(cId);
				// 取cbbTabColumns该tid下的最大排序值
				int num = selectMaxOrder(newId) + 1;
				BigDecimal colOrder = new BigDecimal(num);
				cbbTabColumns.setColOrder(colOrder);
				// 取cbbTabColumns该tableId下的表格最大排序值
				int numTab = selectMaxOrder(newId) + 1;
				BigDecimal colTabOrder = new BigDecimal(numTab);
				cbbTabColumns.setAttribute11(colTabOrder);
				String newColId = insertCbbTabColumus(cbbTabColumns, newId, orgId, deptId, sysId, loginUserId, loginIp);
				columnIdMap.put(cId, newColId);
			}
			// 生成动态表
			insertdbTable(newId, sysId, orgId);
			// 复制信息
			for (int i = 0; i < list.size(); i++) {
				String cId = String.valueOf(list.get(i));// oldTableColId
				String newColId = columnIdMap.get(cId);
				CbbTabColumns cbbTabColumns = getCbbTabColumnsById(newColId);
				// 2.2.复制代码维护信息
				if ("1".equals(cbbTabColumns.getColDropdownType()) || "2".equals(cbbTabColumns.getColDropdownType())) {
					// 复制通用代码信息（CBB_TAB_COL_SYS_CODE表）
					String codeSql = "SELECT T.SYS_LOOKUP_ID,T.REMARK FROM CBB_TAB_COL_SYS_CODE T WHERE T.COLUMN_ID = '" + cId + "'";
					List<Object[]> codeList = this.hibernateDao.findBySQL(codeSql);
					if (codeList != null && codeList.size() > 0) {
						CbbTabColSysCode cbbTabColSysCode = new CbbTabColSysCode();
						cbbTabColSysCode.setSysLookupId(codeList.get(0)[0].toString());
						cbbTabColSysCode.setRemark(codeList.get(0)[1] == null ? "" : codeList.get(0)[1].toString());
						String id = ComUtil.getId();
						cbbTabColSysCode.setId(id);
						cbbTabColSysCode.setTableId(newId);
						cbbTabColSysCode.setColumnId(newColId);
						cbbTabColSysCode.setOrgId(orgId);
						cbbTabColSysCode.setDeptId(deptId);
						cbbTabColSysCode.setSysId(sysId);
						PojoUtil.setSysProperties(cbbTabColSysCode, OpType.insert);
						hibernateDao.save(cbbTabColSysCode);
						SysLogUtil.log(cbbTabColSysCode, null, OpType.insert, OpResult.success);
					}
					// 复制通用代码信息（CBB_TAB_COL_CODE表）
					String codeSql2 = "SELECT T.CODE_ORDER,T.CODE_IS_VALID,T.LOOKUP_NAME,T.LOOKUP_CODE,T.REMARK FROM CBB_TAB_COL_CODE T WHERE T.COLUMN_ID = '" + cId + "'";
					List<Object[]> codeList2 = this.hibernateDao.findBySQL(codeSql2);
					for (int k = 0; k < codeList2.size(); k++) {
						CbbTabColCode cbbTabColCode = new CbbTabColCode();
						cbbTabColCode.setCodeOrder(new BigDecimal(codeList2.get(k)[0].toString()));
						cbbTabColCode.setCodeIsValid(codeList2.get(k)[1].toString());
						cbbTabColCode.setLookupName(codeList2.get(k)[2].toString());
						cbbTabColCode.setLookupCode(codeList2.get(k)[3].toString());
						cbbTabColCode.setRemark(codeList2.get(k)[4] == null ? "" : codeList2.get(k)[4].toString());
						cbbTabColCode.setTableId(newId);
						cbbTabColCode.setColumnId(newColId);
						cbbTabColCode.setDeptId(deptId);
						cbbTabColCode.setOrgId(orgId);
						cbbTabColCode.setSysId(sysId);
						String colCodeId = ComUtil.getId();
						cbbTabColCode.setId(colCodeId);
						PojoUtil.setSysProperties(cbbTabColCode, OpType.insert);
						hibernateDao.save(cbbTabColCode);
						SysLogUtil.log(cbbTabColCode, null, OpType.insert, OpResult.success);
					}
				}
				// 2.3.复制索引信息(INDEX_NAME,INDEX_TYPE，REMARK)
				String indexSql = "SELECT T.INDEX_NAME,T.INDEX_TYPE,T.REMARK FROM CBB_TAB_COL_INDEX T WHERE T.TABLE_ID = '" + oldTableId + "' AND T.COLUMN_ID = '" + cId + "'";
				List<Object[]> indexList = this.hibernateDao.findBySQL(indexSql);
				for (int k = 0; k < indexList.size(); k++) {
					String indexName = String.valueOf(indexList.get(k)[0]);
					indexName = indexName + "_" + (numt + 1);
					String indexType = String.valueOf(indexList.get(k)[1]);
					CbbTabColIndex cbbTabColIndex = new CbbTabColIndex();
					cbbTabColIndex.setIndexName(indexName);
					cbbTabColIndex.setIndexType(indexType);
					cbbTabColIndex.setRemark(indexList.get(k)[2] == null ? "" : indexList.get(k)[2].toString());
					String id = ComUtil.getId();
					cbbTabColIndex.setId(id);
					cbbTabColIndex.setTableId(newId);
					cbbTabColIndex.setColumnId(newColId);
					cbbTabColIndex.setDeptId(deptId);
					cbbTabColIndex.setOrgId(orgId);
					cbbTabColIndex.setSysId(sysId);
					PojoUtil.setSysProperties(cbbTabColIndex, OpType.insert);
					hibernateDao.save(cbbTabColIndex);
					SysLogUtil.log(cbbTabColIndex, null, OpType.insert, OpResult.success);
					if ("1".equals(indexType) && "Y".equals(isTrueTable)) {
						// 添加ORCALE一般索引
						String sql = "CREATE INDEX " + indexName + " ON " + tableName + " (" + cbbTabColumns.getColName() + ")";
						jdbcAvicit.getJdbcTemplate().execute(sql);
						jdbcAvicit.getJdbcTemplate().execute("commit");
						SysLogUtil.log("库结构定义模块", "新增列索引", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
					}
				}
				// 2.4.复制分类搜索信息(search_order,remark)
				String searchSql = "SELECT T.SEARCH_ORDER,T.REMARK FROM CBB_TAB_COL_SEARCH T WHERE T.TABLE_ID = '" + oldTableId + "' AND T.COLUMN_ID = '" + cId + "'";
				List<Object[]> searchList = this.hibernateDao.findBySQL(searchSql);
				for (int k = 0; k < searchList.size(); k++) {
					CbbTabColSearch cbbTabColSearch = new CbbTabColSearch();
					cbbTabColSearch.setSearchOrder(new BigDecimal(searchList.get(k)[0].toString()));
					cbbTabColSearch.setRemark(searchList.get(k)[1] == null ? "" : searchList.get(k)[1].toString());
					String id = ComUtil.getId();
					cbbTabColSearch.setId(id);
					cbbTabColSearch.setTableId(newId);
					cbbTabColSearch.setColumnId(newColId);
					cbbTabColSearch.setDeptId(deptId);
					cbbTabColSearch.setOrgId(orgId);
					cbbTabColSearch.setSysId(sysId);
					PojoUtil.setSysProperties(cbbTabColSearch, OpType.insert);
					hibernateDao.save(cbbTabColSearch);
					SysLogUtil.log(cbbTabColSearch, null, OpType.insert, OpResult.success);
				}
				// 2.5.复制排序信息(sort_order,sort_code,remark)
				String sortSql = "SELECT T.SORT_ORDER,T.SORT_CODE,T.REMARK FROM CBB_TAB_COL_SORT T WHERE T.TABLE_ID = '" + oldTableId + "' AND T.COLUMN_ID = '" + cId + "'";
				List<Object[]> sortList = this.hibernateDao.findBySQL(sortSql);
				for (int k = 0; k < sortList.size(); k++) {
					CbbTabColSort cbbTabColSort = new CbbTabColSort();
					cbbTabColSort.setSortOrder(new BigDecimal(sortList.get(k)[0].toString()));
					cbbTabColSort.setSortCode(sortList.get(k)[1].toString());
					cbbTabColSort.setRemark(sortList.get(k)[2] == null ? "" : sortList.get(k)[2].toString());
					String id = ComUtil.getId();
					cbbTabColSort.setId(id);
					cbbTabColSort.setTableId(newId);
					cbbTabColSort.setColumnId(newColId);
					cbbTabColSort.setDeptId(deptId);
					cbbTabColSort.setOrgId(orgId);
					cbbTabColSort.setSysId(sysId);
					PojoUtil.setSysProperties(cbbTabColSort, OpType.insert);
					hibernateDao.save(cbbTabColSort);
					SysLogUtil.log(cbbTabColSort, null, OpType.insert, OpResult.success);
				}
			}
			// 3.复制CBB_TAB_NODE记录
			String oldTabFlag = String.valueOf(listTab.get(j).get("TAB_FLAG"));// 旧表flag
			Map<String, Object> param = new HashMap<String, Object>();
			param.put("TAB_FLAG", oldTabFlag);
			createCbbTabNodeByIntfs(orgId, deptId, sysId, newNodeId, newId, loginUserId, loginIp, param);
		}
		// 循环更新组合项、统计生成配置信息
		for (int j = 0; j < listTab.size(); j++) {
			String oldTableId = String.valueOf(listTab.get(j).get("ID"));// 旧表ID
			List<Object> list = getColumnsIdByTableId(oldTableId);
			CbbTabColumns[] cbbTabColumnsArray = new CbbTabColumns[list.size()]; // 更新的column对象数组
			for (int i = 0; i < list.size(); i++) {
				String cId = String.valueOf(list.get(i)); // oldColumnId
				CbbTabColumns cbbTabColumns = getCbbTabColumnsById(columnIdMap.get(cId));
				cbbTabColumnsArray[i] = cbbTabColumns;
				// 查找旧字段配置信息
				List<Object[]> configList = getColumnConfigBySourceColId(cId);
				if (configList.size() > 0) {
					String[] configColumns = new String[configList.size()];
					String[] configInput = new String[configList.size()];
					String[] orders = new String[configList.size()];
					String operation = "";
					String colGeneMethoRule = "";
					for (int k = 0; k < configList.size(); k++) {
						String tgtTableId = (String) configList.get(k)[0];
						String tgtColId = (String) configList.get(k)[1];
						String tgtInput = (String) configList.get(k)[2];
						operation = (String) configList.get(k)[3];
						// 更换旧表ID、旧字段ID
						String newTableId = tableIdMap.get(tgtTableId);
						String newColumnId = columnIdMap.get(tgtColId);
						configColumns[k] = newTableId + "," + newColumnId;
						configInput[k] = tgtInput;
						orders[k] = k + 1 + "";
						colGeneMethoRule = colGeneMethoRule + newTableId + "," + newColumnId + "+";
						if (null != tgtInput && !"".equals(tgtInput) && !"null".equals(tgtInput)) {
							colGeneMethoRule = colGeneMethoRule + "\"" + tgtInput + "\"+";
						}
					}
					if (!"".equals(colGeneMethoRule)) {
						cbbTabColumns.setColGeneMethodRule(colGeneMethoRule.substring(0, colGeneMethoRule.length() - 1));
					}
					// 保存配置信息
					if ("4".equals(cbbTabColumns.getColGeneMethod())) {
						commTableManagerService.saveConfigGroup(columnIdMap.get(cId), configColumns, configInput, tableIdMap.get(oldTableId), orgId, deptId, sysId, orders);
					} else if ("5".equals(cbbTabColumns.getColGeneMethod())) {
						commTableManagerService.saveConfigTJSC(columnIdMap.get(cId), configColumns, configInput, tableIdMap.get(oldTableId), orgId, deptId, sysId, orders, operation);
					}
				}
			}
			// 更新column对象
			commTableManagerService.updateCbbTabColumnsTemp(cbbTabColumnsArray, sysId, "", "");
		}
	}

	/**
	 * 创建表与节点关联关系
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param tableId
	 * @param param
	 * 				key:TAB_FLAG value:string (结构类型 0：案卷级，1：盒级)
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void createCbbTabNodeByIntfs(String orgId, String deptId, String sysId, String nodeId, String tableId, String loginUserId, String loginIp, Map<String, Object> param) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String nid = ComUtil.getId();
		// 取CBB_TAB_NODE该TABLE_ID,NODE_ID,SYS_ID下的最大排序值
		int tnum = selectMaxSort(nodeId, sysId) + 1;
		BigDecimal sortOrder = new BigDecimal(tnum);
		String tabFlag = "";
		if (param.containsKey("TAB_FLAG")) {
			tabFlag = String.valueOf(param.get("TAB_FLAG"));
			if (tabFlag == null || "null".equals(tabFlag)) {
				tabFlag = "";
			}
		}
		try {
			StringBuffer sbSql = new StringBuffer();
			sbSql.append("INSERT INTO CBB_TAB_NODE\n");
			sbSql.append("  (ID,\n");
			sbSql.append("   TABLE_ID,\n");
			sbSql.append("   NODE_ID,\n");
			sbSql.append("   TAB_ORDER,\n");
			sbSql.append("   REMARK,\n");
			sbSql.append("   ORG_ID,\n");
			sbSql.append("   DEPT_ID,\n");
			sbSql.append("   SYS_ID,\n");
			sbSql.append("   SECRET_LEVEL,\n");
			sbSql.append("   SYS_APPLICATION_ID,\n");
			sbSql.append("   LAST_UPDATE_DATE,\n");
			sbSql.append("   LAST_UPDATED_BY,\n");
			sbSql.append("   CREATION_DATE,\n");
			sbSql.append("   CREATED_BY,\n");
			sbSql.append("   LAST_UPDATE_IP,\n");
			sbSql.append("   VERSION,\n");
			sbSql.append("   TAB_FLAG)\n");
			sbSql.append("VALUES\n");
			sbSql.append("  ('" + nid + "',\n");
			sbSql.append("   '" + tableId + "',\n");
			sbSql.append("   '" + nodeId + "',\n");
			sbSql.append("   " + sortOrder + ",\n");
			sbSql.append("   '',\n");
			sbSql.append("   '" + orgId + "',\n");
			sbSql.append("   '" + deptId + "',\n");
			sbSql.append("   '" + sysId + "',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   SYSDATE,\n");
			sbSql.append("   '" + loginUserId + "',\n");
			sbSql.append("   SYSDATE,\n");
			sbSql.append("   '" + loginUserId + "',\n");
			sbSql.append("   '" + loginIp + "',\n");
			sbSql.append("   1,\n");
			sbSql.append("   '" + tabFlag + "')");
			jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
			jdbcAvicit.getJdbcTemplate().execute("commit");
			SysLogUtil.log("库结构定义模块", "新增表与节点关联关系记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
		} catch (Exception e) {
			e.printStackTrace();
			SysLogUtil.log("库接口定义模块", "新增表与节点关联关系记录", OpType.insert, OpResult.failure, LogBaseFactory.getLogBase());
		}

	}

	/**
	 * 创建节点著录定义
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param tableId
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void createCbbTabNodeRecordByIntfs(String orgId, String deptId, String sysId, String nodeId, String tableId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String tabNodeId = getCbbTabNodeIdByIntfs(orgId, deptId, sysId, nodeId, tableId);// 关联关系表ID
		List<Object> listColumnsIds = getColumnsIdByTableId(tableId);
		for (int i = 0; i < listColumnsIds.size(); i++) {
			String columnsId = String.valueOf(listColumnsIds.get(i));
			CbbTabColumns cbbTabColumns = getCbbTabColumnsById(columnsId);// 获取columns对象
			CbbTabNodeRecord cbbTabNodeRecord = new CbbTabNodeRecord();
			String id = ComUtil.getId();
			cbbTabNodeRecord.setId(id);
			cbbTabNodeRecord.setTabNodeId(tabNodeId);
			cbbTabNodeRecord.setColumnId(cbbTabColumns.getId());
			cbbTabNodeRecord.setColIsVisible(cbbTabColumns.getColIsVisible());
			cbbTabNodeRecord.setColIsTabVisible(cbbTabColumns.getColIsTabVisible());
			cbbTabNodeRecord.setColIsDetail(cbbTabColumns.getColIsDetail());
			cbbTabNodeRecord.setOrgId(orgId);
			cbbTabNodeRecord.setDeptId(deptId);
			cbbTabNodeRecord.setSysId(sysId);
			PojoUtil.setSysProperties(cbbTabNodeRecord, OpType.insert);
			hibernateDao.save(cbbTabNodeRecord);
			SysLogUtil.log(cbbTabNodeRecord, null, OpType.insert, OpResult.success);
		}

	}

	/**
	 * 创建库表
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tabLevel
	 *            （库表层级）
	 * @param moreLevelName
	 *            （多层级名称字符串，使用分号隔开）
	 * @param loginUserId
	 *            （userId）
	 * @param loginIp
	 *            （ip）
	 * @param ifTrue
	 *            （是否为真实表）
	 * @param param
	 *				key:TAB_FLAG value:string (结构类型 0：案卷级，1：盒级)
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void createCbbTableByIntfs(String orgId, String deptId, String sysId, String nodeId, String nodeName, String tabLevel, String moreLevelName, String loginUserId, String loginIp, boolean ifTrue, String nodeCode, Map<String, Object> param) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String tableTitle = "";
		String tabFlag = "";
		String tempwenIds = "";//案卷级模板ID串
		String tempanIds = ""; //文件级模板ID串
		if (param.containsKey("TAB_FLAG")) {
			tabFlag = String.valueOf(param.get("TAB_FLAG"));
		} else {
			throw new Exception("调用方法时TAB_FLAG参数不存在，请检查！");
		}
		if (param.containsKey("tempwenIds")) {
			tempwenIds = String.valueOf(param.get("tempwenIds"));
		}
		if (param.containsKey("tempanIds")) {
			tempanIds = String.valueOf(param.get("tempanIds"));
		}
		boolean isTech = false;// 是否为技术资料动态管理
		if (param.containsKey("isTech")) {
			isTech = (Boolean) param.get("isTech");
		}
		Map<String, Object> param2 = new HashMap<String, Object>();
		param2.put("TAB_FLAG", tabFlag);
		if ("1".equals(tabLevel)) {
			if (ifTrue) {
				tableTitle = nodeName + "_文件";
			} else {
				tableTitle = nodeName;
			}
			param2.put("templetModelId", tempwenIds); // 参考模板对应id串
			createTabForm(orgId, deptId, sysId, nodeId, nodeName, tableTitle, "_WJ", loginUserId, loginIp, ifTrue, nodeCode, param2);
		} else if ("2".equals(tabLevel)) {
			String tableCodeAjj = "";
			tableTitle = nodeName + "_案卷级";
			if ("1".equals(tabFlag)) {
				tableTitle = nodeName + "_盒级";
			}
			if (!ifTrue) {
				tableCodeAjj = nodeCode + "_AJJ";
			} else {
				tableCodeAjj = nodeCode;
			}
			param2.put("templetModelId", tempanIds); // 参考模板对应id串
			createTabForm(orgId, deptId, sysId, nodeId, nodeName, tableTitle, "_AJJ", loginUserId, loginIp, ifTrue, tableCodeAjj, param2);
			String tableCodeWjj = "";
			tableTitle = nodeName + "_文件级";
			if (!ifTrue) {
				tableCodeWjj = nodeCode + "_WJJ";
			} else {
				tableCodeWjj = nodeCode;
			}
			param2.put("templetModelId", tempwenIds); // 参考模板对应id串
			createTabForm(orgId, deptId, sysId, nodeId, nodeName, tableTitle, "_WJJ", loginUserId, loginIp, ifTrue, tableCodeWjj, param2);
		}
		if (isTech) {// 如果为技术资料动态管理库表
			String tableNameFix = "";
			if ("1".equals(tabLevel)) {
				tableNameFix = "_WJ";
			} else {
				tableNameFix = "_WJJ";
			}
			createTabFormBytech(orgId, deptId, sysId, nodeId, nodeName, tableTitle, tableNameFix, loginUserId, loginIp, nodeCode, param2);
		}
	}

	/**
	 * 根据模板类型和组织id查询所有参考模板信息ID
	 *
	 * @param orgId
	 * @param modelType
	 * @return
	 */
	private String queryTempletModelByOrgIdAndModelType(String orgId, String modelType) {
		String templetModelId = "";
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		String sql = "SELECT T.ID FROM CBB_TEMPLET_INFO T WHERE (T.ORG_ID = 'ORG_ROOT' OR T.ORG_ID = '" + orgId + "') AND T.TEMP_MODEL_TYPE = '" + modelType + "'";
		list = this.jdbcAvicit.queryForMap(sql, null);
		if (list.size() > 0) {
			for (Map<String, Object> map : list) {
				String id = (String) map.get("ID");
				templetModelId = templetModelId + id + ",";
			}
			templetModelId = templetModelId.substring(0, templetModelId.length() - 1);
		}
		return templetModelId;
	}

	/**
	 * 节点著录定义删除字段信息
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param tableId
	 * @param colId
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void deleteCbbTabNodeRecordFieldByIntfs(String orgId, String deptId, String sysId, String nodeId, String tableId, String colId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String tabNodeId = getCbbTabNodeIdByIntfs(orgId, deptId, sysId, nodeId, tableId);// 查询tabNodeId
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("DELETE FROM CBB_TAB_NODE_RECORD T WHERE  T.COLUMN_ID = '" + colId + "' AND T.TAB_NODE_ID = '" + tabNodeId + "' AND T.ORG_ID = '" + orgId + "' AND T.SYS_ID = '" + sysId + "'");
		jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
		SysLogUtil.log("库结构定义模块", "删除著录定义记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	/**
	 * 根据节点ID，删除库表信息（所有与库表相关的信息）
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param isTrueTable
	 *            (0 虚拟表 1 真实表)
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void deleteCbbTableByNodeIdByIntfs(String orgId, String deptId, String sysId, String nodeId, String isTrueTable) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> listTab = this.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "");// 获取oldTableId
		for (int j = 0; j < listTab.size(); j++) {
			String tableId = String.valueOf(listTab.get(j).get("ID"));// 表ID
			// addby gl 2016-06-07 atart 删除库表时同步更新配置信息
			// 1、删除表单配置信息
			// 1.1、 查找tabNodeId
			String tabNodeId = commTableManagerService.getCbbTabNodeId(sysId, nodeId, tableId);
			// 1.2、根据tabNodeId查找formId
			String formId = billDefineManagerService.getFormIdByTableNodeId(tabNodeId);
			// 1.3、根据formId删除表单配置信息
			billDefineManagerService.deleteFormDataByFormId(formId);
			// 2、 删除节点著录定义配置信息
			// 2.1、 根据tableId查找tabNodeId
			List<Object> list = commTableManagerService.getCbbTabNodeIdByTableId(sysId, tableId, nodeId);
			if (list.size() > 0) {
				for (Object obj : list) {
					// 2.2、根据tabNodeId删除节点著录定义配置信息
					commTableManagerService.deleteCbbTabNodeRecordByTabNodeId(String.valueOf(obj));
				}
			}
			// addby gl 2016-06-07 end 删除库表时同步更新配置信息
			// 删除组合项、统计生成配置信息 add by gl 2016-06-28 start
			commTableManagerService.deleteGroupConfigByTableId(tableId);
			// 删除组合项、统计生成配置信息 add by gl 2016-06-28 end
			// 调用存储过程删除库表数据
			ArrayList<Object> params = new ArrayList<Object>();
			params.add(0, tableId);
			params.add(1, sysId.toUpperCase());
			params.add(2, nodeId);
			params.add(3, isTrueTable);
			params.add(4, orgId);
			commTableManagerDao.callProcedure("CBB_TABLEDEFINE_P.DELETE_TABLE_INFO", params);
			SysLogUtil.log("库结构定义模块", "删除库表记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
		}
	}

	/**
	 * 获取系统初始字段信息
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbSysInitFieldsByIntfs(String orgId, String deptId, String sysId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> listSysInitField = new ArrayList<Map<String, Object>>();
		String templetId = getCbbTempletInfoIdBySysId(sysId.toUpperCase(), orgId);// templetId
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.* FROM CBB_TEMPLET_FIELD T WHERE  T.TEMPLET_ID = '" + templetId + "' ");
		sbSql.append(" ORDER BY T.COL_ORDER,T.COL_NAME\n");
		// if (!"".equals(deptId)) {
		// sbSql.append(" AND T.DEPT_ID = '" + deptId + "'");
		// }
		listSysInitField = jdbcAvicit.queryForMap(sbSql.toString(), null);
		return listSysInitField;
	}

	/**
	 * 根据字段类型，获取系统初始字段信息
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param colType
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbSysInitFieldsByColTypeByIntfs(String orgId, String deptId, String sysId, String colType) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> listFields = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.* FROM CBB_TEMPLET_FIELD T WHERE T.COL_TYPE = '" + colType.toLowerCase() + "' AND T.ORG_ID = '" + orgId + "' AND T.SYS_ID = '" + sysId + "' AND T.COL_IS_SYS = 'Y'");
		sbSql.append(" ORDER BY T.COL_ORDER,T.COL_NAME\n");
		listFields = jdbcAvicit.queryForMap(sbSql.toString(), null);
		return listFields;
	}

	/**
	 * 获取字段信息
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param tableId
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbTabColumnsByIntfs(String orgId, String deptId, String sysId, String nodeId, String tableId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> listFields = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.* FROM CBB_TAB_COLUMNS T WHERE T.COL_IS_DISPLAY = 'Y' AND T.TABLE_ID = '" + tableId + "' AND T.ORG_ID = '" + orgId + "' AND T.SYS_ID = '" + sysId + "'");
		sbSql.append(" ORDER BY T.COL_ORDER,T.COL_NAME\n");
		listFields = jdbcAvicit.queryForMap(sbSql.toString(), null);
		// 查找节点著录定义配置信息，如果有配置信息，覆盖旧值返回
		List<Object> tabNodeIdList = getCbbTabNodeIdByTableId(sysId, tableId, nodeId);
		if (tabNodeIdList.size() > 0) {
			for (int i = 0; i < tabNodeIdList.size(); i++) {
				String tabNodeId = (String) tabNodeIdList.get(i);
				List<Map<String, Object>> nodeRecordList = getTabNodeRecordInfoByTabNodeId(tabNodeId);
				if (nodeRecordList.size() > 0) {
					for (Map<String, Object> nodeRecordMap : nodeRecordList) {
						String colId = (String) nodeRecordMap.get("COLUMN_ID");
						String isVisible = (String) nodeRecordMap.get("COL_IS_VISIBLE");
						String isTabVisible = (String) nodeRecordMap.get("COL_IS_TAB_VISIBLE");
						String isDetail = (String) nodeRecordMap.get("COL_IS_DETAIL");
						String isSearch = (String) nodeRecordMap.get("COL_IS_SEARCH");
						for (Map<String, Object> tabColumnMap : listFields) {
							if (colId.equals(tabColumnMap.get("ID"))) {
								tabColumnMap.put("COL_IS_VISIBLE", isVisible);
								tabColumnMap.put("COL_IS_TAB_VISIBLE", isTabVisible);
								tabColumnMap.put("COL_IS_DETAIL", isDetail);
								tabColumnMap.put("COL_IS_SEARCH", isSearch);
							}
						}
					}
				}
			}
		}
		return listFields;
	}

	/**
	 * 根据tabNodeId获取节点著录定义配置信息
	 * @author 郭亮
	 * @param tabNodeId 表与节点关系ID，必填
	 * @return
	 * @throws Exception List<Map<String,Object>>
	 */
	public List<Map<String, Object>> getTabNodeRecordInfoByTabNodeId(String tabNodeId) throws Exception {
		if (null == tabNodeId || "".equals(tabNodeId) || "null".equals(tabNodeId)) {
			throw new Exception("调用方法时tabNodeId参数不存在，请检查！");
		}
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		String sql = "SELECT T.* FROM CBB_TAB_NODE_RECORD T WHERE T.TAB_NODE_ID = '" + tabNodeId + "'";
		list = jdbcAvicit.queryForMap(sql, null);
		return list;
	}

	/**
	 * 根据tableId、nodeId获取tabNodeId（文件类型取‘个人文件’‘部门文件’节点ID作为tabNodeId）
	 * @author 郭亮
	 * @param sysId 必填
	 * @param tableId 必填
	 * @param nodeId
	 * @return
	 * @throws Exception List<Object>
	 */
	public List<Object> getCbbTabNodeIdByTableId(String sysId, String tableId, String nodeId) throws Exception {
		if (null == sysId || "".equals(sysId) || "null".equals(sysId)) {
			throw new Exception("调用方法时sysId参数不存在，请检查！");
		}
		if (null == tableId || "".equals(tableId) || "null".equals(tableId)) {
			throw new Exception("调用方法时tableId参数不存在，请检查！");
		}
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Object> objList = new ArrayList<Object>();
		// 1、根据tableId查找nodeId
		String nodeIdSql = "SELECT T.NODE_ID FROM CBB_TAB_NODE T WHERE T.TABLE_ID = '" + tableId + "'";
		List<String> nodeIdLsit = this.hibernateDao.findBySQL(nodeIdSql);
		if (nodeIdLsit.size() > 0) {
			String parentIds = ""; // nodeID，多个时以英文逗号分割
			for (String str : nodeIdLsit) {
				parentIds = parentIds + "," + str;
			}
			if (!"".equals(parentIds)) {
				parentIds = parentIds.substring(1);
			}
			// 2、将nodeId作为parentId查找lantop_archive节点
			// 调用rest服务
			CbbArchiveClassRestClient cbbArchiveClassRestClient = new CbbArchiveClassRestClient("/api/im/lantop/basic/archiveclass");
			ResponseMsg<String> responseMsg = RestClient.doPost(cbbArchiveClassRestClient.getRestUrl("/getNodeIdByParentId/v1"), parentIds, new GenericType<ResponseMsg<String>>() {
			});
			if (responseMsg.getRetCode().equals(ResponseStatus.HTTP_OK)) {
				String tabNodeIds = responseMsg.getResponseBody(); // tabnodeId，多个以英文逗号分割
				if (null != tabNodeIds && !"".equals(tabNodeIds) && !"null".equals(tabNodeIds)) {
					// 文件类型，获取rest服务返回结果
					String[] tabNodeIdArr = tabNodeIds.split(",");
					for (String tabNodeId : tabNodeIdArr) {
						objList.add(tabNodeId);
					}
				} else {
					// 非文件类型，通过sql查找tabNodeId
					StringBuffer sbSql = new StringBuffer();
					sbSql.append("SELECT T.ID\n");
					sbSql.append(" FROM CBB_TAB_NODE T\n");
					sbSql.append(" WHERE T.TABLE_ID = '" + tableId + "'\n");
					sbSql.append(" AND T.SYS_ID = '" + sysId + "'\n");
					if (null != nodeId && !"".equals(nodeId) && !"null".equals(nodeId)) {
						sbSql.append(" AND T.NODE_ID = '" + nodeId + "'");
					}
					objList = hibernateDao.findBySQL(sbSql.toString());
				}
			} else {
				throw new RuntimeException(responseMsg.getErrorDesc());
			}
		}
		return objList;
	}

	/**
	 * 获取表与节点关系ID
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param tableId
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 */
	@Override
	public String getCbbTabNodeIdByIntfs(String orgId, String deptId, String sysId, String nodeId, String tableId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String nid = "";
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID FROM CBB_TAB_NODE T WHERE T.TABLE_ID = '" + tableId + "' AND T.NODE_ID = '" + nodeId + "' AND T.ORG_ID = '" + orgId + "' AND T.SYS_ID = '" + sysId + "'");
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		if (objList != null && objList.size() > 0) {
			nid = String.valueOf(objList.get(0));
		}
		return nid;
	}

	/**
	 * 根据系统标识ID，表名，获取表ID
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param tableName
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 */
	@Override
	public String getCbbTableIdByIntfs(String orgId, String deptId, String sysId, String tableName) throws Exception {
		if (null == sysId || "".equals(sysId) || "null".equals(sysId)) {
			throw new Exception("调用方法时sysId参数不存在，请检查！");
		}
		if (null == orgId || "".equals(orgId) || "null".equals(orgId)) {
			throw new Exception("调用方法时orgId参数不存在，请检查！");
		}
		if (null == tableName || "".equals(tableName) || "null".equals(tableName)) {
			throw new Exception("调用方法时tableName参数不存在，请检查！");
		}
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		String tableId = "";
		StringBuffer sbSql = new StringBuffer();
		if (tableName.equals("LANTOP_PUB_FIELD")) {// 如果是公共字段，那么不进行组织过滤，临时使用
			sbSql.append("SELECT T.ID FROM CBB_TABLES T WHERE T.TABLE_NAME = '" + tableName + "'" + " AND T.SYS_ID = '" + sysId + "'");
		} else {
			sbSql.append("SELECT T.ID FROM CBB_TABLES T WHERE T.TABLE_NAME = '" + tableName + "'" + " AND T.SYS_ID = '" + sysId + "' AND T.ORG_ID = '" + orgId + "'");
		}
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		if (objList != null && objList.size() > 0) {
			tableId = String.valueOf(objList.get(0));
		}
		return tableId;
	}

	/**
	 * 根据表名，获取表ID
	 *
	 * @author 朱锋
	 * @param tableName
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 */
	@Override
	public String getCbbTableIdByTableNameIntfs(String tableName) throws Exception {
		if (null == tableName || "".equals(tableName) || "null".equals(tableName)) {
			throw new Exception("调用方法时tableName参数不存在，请检查！");
		}
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		String tableId = "";
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID FROM CBB_TABLES T WHERE T.TABLE_NAME = '" + tableName + "'");
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		if (objList != null && objList.size() > 0) {
			tableId = String.valueOf(objList.get(0));
		}
		return tableId;
	}

	/**
	 * 获取库表信息
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param cbbTableIndex
	 *            （表索引：1，2，3...N）
	 * @return  List<Map<String,Object>>
	 *             案卷级盒级判断标识 key : TAB_FLAG  value : 0（案卷级），1（盒级）
	 * @throws Exception
	 */
	@Override
	public List<Map<String, Object>> getCbbTableInfoByNodeIdByIntfs(String orgId, String deptId, String sysId, String nodeId, String cbbTableIndex) throws Exception {
//		sysId = sysId.toUpperCase(); // 将参数转换为大写
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.*,CTN.TAB_FLAG\n");
		sbSql.append("  FROM CBB_TABLES T\n");
		sbSql.append("  LEFT JOIN CBB_TAB_NODE CTN\n");
		sbSql.append("    ON CTN.TABLE_ID = T.ID\n");
		sbSql.append(" WHERE CTN.NODE_ID = '" + nodeId + "'\n");
		// sbSql.append("   AND CTN.ORG_ID = '" + orgId + "'\n");
		sbSql.append("   AND CTN.SYS_ID = '" + sysId + "'");
		if (!"".equals(cbbTableIndex)) {
			sbSql.append("   AND CTN.TAB_ORDER = " + cbbTableIndex);
		}
		sbSql.append(" ORDER BY CTN.TAB_ORDER ASC");
		List<Map<String, Object>> listFields = jdbcAvicit.queryForMap(sbSql.toString(), null);
		return listFields;
	}

	/**
	 * 根据表ID，获取节点信息
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param tableId
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getNodesByTableIdSysIdByIntfs(String orgId, String deptId, String sysId, String tableId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.NODE_ID, T.TAB_ORDER\n");
		sbSql.append("  FROM CBB_TAB_NODE T\n");
		sbSql.append(" WHERE T.TABLE_ID = '" + tableId + "'\n");
		sbSql.append("   AND T.SYS_ID = '" + sysId + "'\n");
		sbSql.append("   AND T.ORG_ID = '" + orgId + "'");
		list = jdbcAvicit.queryForMap(sbSql.toString(), null);
		return list;
	}

	/**
	 * 根据节点ID和表ID，删除表与节点关联关系
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param tableId
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void deleteCbbTabNodeByNodeIdAndTabIdByIntfs(String orgId, String deptId, String sysId, String nodeId, String tableId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("DELETE FROM CBB_TAB_NODE T\n");
		sbSql.append(" WHERE T.TABLE_ID = '" + sbSql + "'\n");
		sbSql.append("   AND T.NODE_ID = '" + nodeId + "'\n");
		sbSql.append("   AND T.ORG_ID = '" + orgId + "'\n");
		sbSql.append("   AND T.SYS_ID = '" + sysId + "'");
		jdbcAvicit.getJdbcTemplate().update(sbSql.toString());
		SysLogUtil.log("库结构定义模块", "删除表与节点关系记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	/**
	 * 根据节点ID，删除表与节点关联关系
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @throws Exception
	 *             void
	 * @throws
	 */
	@Override
	public void deleteCbbTabNodeByNodeIdByIntfs(String orgId, String deptId, String sysId, String nodeId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("DELETE FROM CBB_TAB_NODE T WHERE T.NODE_ID = '" + nodeId + "' AND T.ORG_ID = '" + orgId + "' AND T.SYS_ID = '" + sysId + "'");
		jdbcAvicit.getJdbcTemplate().update(sbSql.toString());
		SysLogUtil.log("库结构定义模块", "删除表与节点关系记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	/**
	 * 根据节点ID，获取表IDS
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbTableIdsByNodeIdByIntfs(String orgId, String deptId, String sysId, String nodeId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> listTableIds = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.TABLE_ID,T.TAB_FLAG\n");
		sbSql.append("  FROM CBB_TAB_NODE T\n");
		sbSql.append(" WHERE T.NODE_ID = '" + nodeId + "'\n");
		//sbSql.append("   AND T.ORG_ID = '" + orgId + "'\n");
		sbSql.append("   AND T.SYS_ID = '" + sysId + "'\n");
		sbSql.append(" ORDER BY T.TAB_ORDER ASC");
		listTableIds = jdbcAvicit.queryForMap(sbSql.toString(), null);
		return listTableIds;
	}

	/**
	 * 根据表ID，获取表信息以及列信息
	 *
	 * @author 朱锋
	 * @param tableId
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbTableAndColumnsByTabIdByIntfs(String tableId) throws Exception {
		List<Map<String, Object>> listTableAndColumns = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CT.ID                  AS TABLE_ID,\n");
		sbSql.append("       CT.TABLE_NAME,\n");
		sbSql.append("       CT.TABLE_TITLE,\n");
		sbSql.append("       CT.ORG_ID,\n");
		sbSql.append("       CT.DEPT_ID,\n");
		sbSql.append("       CTC.ID                 AS COL_ID,\n");
		sbSql.append("       CTC.COL_NAME,\n");
		sbSql.append("       CTC.COL_LABEL,\n");
		sbSql.append("       CTC.COL_TYPE,\n");
		sbSql.append("       CTC.COL_LENGTH,\n");
		sbSql.append("       CTC.COL_DECIMAL,\n");
		sbSql.append("       CTC.COL_IS_SYS,\n");
		sbSql.append("       CTC.COL_ORDER,\n");
		sbSql.append("       CTC.COL_IS_MUST,\n");
		sbSql.append("       CTC.COL_IS_VISIBLE,\n");
		sbSql.append("       CTC.COL_IS_SEARCH,\n");
		sbSql.append("       CTC.COL_IS_EDIT,\n");
		sbSql.append("       CTC.COL_IS_TAB_VISIBLE,\n");
		sbSql.append("       CTC.COL_IS_DETAIL,\n");
		sbSql.append("       CTC.COL_DROPDOWN_TYPE,\n");
		sbSql.append("       CTC.COL_GENE_METHOD,\n");
		sbSql.append("       CTC.COL_RULE_NAME,\n");
		sbSql.append("       CTC.COL_RULE_TITLE,\n");
		sbSql.append("       CTC.CUSTOM_PATH,\n");
		sbSql.append("       CTC.REMARK,\n");
		sbSql.append("       CTC.COL_SHOW_FORMAT,\n");
		sbSql.append("       CTC.COL_GENE_METHOD_RULE,\n");
		sbSql.append("       CTC.COL_IS_DISPLAY\n");
		sbSql.append("  FROM CBB_TABLES CT\n");
		sbSql.append(" INNER JOIN CBB_TAB_COLUMNS CTC\n");
		sbSql.append("    ON CTC.TABLE_ID = CT.ID\n");
		if(tableId.length() == 32){
			sbSql.append(" WHERE CT.ID = '" + tableId + "'");
		}else{
			sbSql.append(" WHERE CT.TABLE_TITLE = '" + tableId + "'");
		}
		sbSql.append(" ORDER BY CTC.COL_ORDER,CTC.COL_NAME\n");
		listTableAndColumns = jdbcAvicit.queryForMap(sbSql.toString(), null);
		// 查找节点著录定义配置信息，如果有配置信息，覆盖旧值返回

		return listTableAndColumns;
	}

	/**
	 * 根据节点ID，获取最大表名
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 */
	@Override
	public String getCbbMaxTableNameByNodeIdByIntfs(String orgId, String deptId, String sysId, String nodeId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String tableName = "";
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CTN.TAB_ORDER,CT.TABLE_NAME\n");
		sbSql.append("  FROM CBB_TAB_NODE CTN\n");
		sbSql.append("  LEFT JOIN CBB_TABLES CT\n");
		sbSql.append("    ON CT.ID = CTN.TABLE_ID\n");
		sbSql.append(" WHERE CTN.NODE_ID = '" + nodeId + "'\n");
		sbSql.append("   AND CTN.ORG_ID = '" + orgId + "'\n");
		sbSql.append("   AND CTN.SYS_ID = '" + sysId + "'\n");
		sbSql.append(" ORDER BY CTN.TAB_ORDER DESC");
		List<Object[]> objList = hibernateDao.findBySQL(sbSql.toString());
		if (objList != null && objList.size() > 0) {
			Object[] obj = objList.get(0);
			tableName = String.valueOf(obj[1]);
		}
		return tableName;
	}

	/**
	 * 获取某系统标识下已定义的所有物理表信息
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbAllTablesBySysIdByIntfs(String orgId, String deptId, String sysId) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> listTable = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CT.ID,CT.TABLE_TITLE,CT.TABLE_NAME,CT.IS_VISIBLE,CT.REMARK FROM CBB_TABLES CT WHERE CT.SYS_ID = '" + sysId + "' AND CT.ORG_ID = '" + orgId + "'");
		listTable = jdbcAvicit.queryForMap(sbSql.toString(), null);
		return listTable;
	}

	/**
	 * 根据表名，获取表信息以及列信息
	 *
	 * @author 朱锋
	 * @param tableName
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbTableAndColumnsByTabNameByIntfs(String orgId, String deptId, String sysId, String tableName) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		String tableId = getCbbTableIdByIntfs(orgId, deptId, sysId, tableName);// 获取TABLEID
		List<Map<String, Object>> list = this.getCbbTableAndColumnsByTabIdByIntfs(tableId);
		for (Map<String,Object> map : list){
			if (map.get("COL_NAME").toString().equals("SQH")) { // 更新档号字段名称（英文）ARCHIVE_CODE
				map.put("COL_NAME", "ARCHIVE_CODE");
			}
			if (map.get("COL_NAME").toString().equals("ZRZ")) { // 责任者
				map.put("COL_NAME", "RESPONSIBLE_USER");
			}
			if (map.get("COL_NAME").toString().equals("MJ")) { // 密级
				map.put("COL_NAME", "SECRET_LEVEL");
			}
			if (map.get("COL_NAME").toString().equals("BGQX")) { // 保管期限
				map.put("COL_NAME", "ARCHIVE_MANA_PERIOD");
			}
			if (map.get("COL_NAME").toString().equals("GDSJ")) { // 归档时间
				map.put("COL_NAME", "ARCHIVE_ACT_DATE");
			}
			if (map.get("COL_NAME").toString().equals("GDDW")) { // 归档单位
				map.put("COL_NAME", "ARCHIVE_DEPT");
			}
			if (map.get("COL_NAME").toString().equals("COL1")) { // 事件号
				map.put("COL_NAME", "SJH");
			}
			if (map.get("COL_NAME").toString().equals("COL2")) { // 事件主题
				map.put("COL_NAME", "SJZT");
			}
		}
		return list;
	}
	/**
	* @Title: getCbbTableAndColumnsByTabNameByIntfsItera
	* @Description:  我的订阅独有的查询公共字段方法
	* @param orgId
	* @param deptId
	* @param sysId
	* @param tableName
	* @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
	* @date 2019-10-12
	* @author HuangJian
	*/
	@Override
	public List<Map<String, Object>> getCbbTableAndColumnsByTabNameByIntfsItera(String orgId, String deptId, String sysId, String tableName) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		String tableId = getCbbTableIdByIntfs(orgId, deptId, sysId, tableName);// 获取TABLEID
		List<Map<String, Object>> list = this.getCbbTableAndColumnsByTabIdByIntfs(tableId);
		for (Map<String,Object> map : list){
			if (map.get("COL_NAME").toString().equals("SQH")) { // 更新档号字段名称（英文）ARCHIVE_CODE
				map.put("COL_NAME", "ARCHIVE_CODE");
			}
			if (map.get("COL_NAME").toString().equals("ZRZ")) { // 责任者
				map.put("COL_NAME", "RESPONSIBLE_USER");
			}
			if (map.get("COL_NAME").toString().equals("MJ")) { // 密级
				map.put("COL_NAME", "SECRET_LEVEL");
			}
			if (map.get("COL_NAME").toString().equals("BGQX")) { // 保管期限
				map.put("COL_NAME", "ARCHIVE_MANA_PERIOD");
			}
			if (map.get("COL_NAME").toString().equals("GDSJ")) { // 归档时间
				map.put("COL_NAME", "ARCHIVE_ACT_DATE");
			}
			if (map.get("COL_NAME").toString().equals("GDDW")) { // 归档单位
				map.put("COL_NAME", "ARCHIVE_DEPT");
			}
			if (map.get("COL_NAME").toString().equals("COL1")) { // 事件号
				map.put("COL_NAME", "SJH");
			}
			if (map.get("COL_NAME").toString().equals("COL2")) { // 事件主题
				map.put("COL_NAME", "SJZT");
			}
			if (map.get("COL_NAME").toString().equals("ND")) { // 年度
				map.put("COL_NAME", "YEAR");
			}
		}
		return list;
	}

	/**
	 * 只根据根据表名，获取表信息以及列信息
	 *
	 * @author 朱锋
	 * @param tableName
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbTableAndColumnsByOnlyTabNameByIntfs(String tableName) throws Exception {
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		String tableId = getCbbTableIdByTableNameIntfs(tableName);// 获取TABLEID
		List<Map<String, Object>> list = this.getCbbTableAndColumnsByTabIdByIntfs(tableId);
		return list;
	}

	/**
	 * 根据标识条件，获取字段信息
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param tableName
	 * @param isAll
	 *            （Y：获取所有字段信息；N：设置为可见的系统字段）
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbFieldsByIsAllByIntfs(String orgId, String deptId, String sysId, String tableName, String isAll) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> listDatas = new ArrayList<Map<String, Object>>();
		String tableId = getCbbTableIdByIntfs(orgId, deptId, sysId, tableName);// 获取TABLEID
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CTC.ID,\n");
		sbSql.append("       CTC.TABLE_ID AS TID,\n");
		sbSql.append("       CTC.COL_NAME,\n");
		sbSql.append("       CTC.COL_LABEL,\n");
		sbSql.append("       CTC.COL_TYPE,\n");
		sbSql.append("       CTC.COL_LENGTH,\n");
		sbSql.append("       CTC.COL_DECIMAL,\n");
		sbSql.append("       CTC.COL_IS_SYS,\n");
		sbSql.append("       CTC.COL_ORDER,\n");
		sbSql.append("       CTC.COL_IS_MUST,\n");
		sbSql.append("       CTC.COL_IS_VISIBLE,\n");
		sbSql.append("       CTC.COL_IS_SEARCH,\n");
		sbSql.append("       CTC.COL_IS_EDIT,\n");
		sbSql.append("       CTC.COL_IS_TAB_VISIBLE,\n");
		sbSql.append("       CTC.COL_IS_DETAIL,\n");
		sbSql.append("       CTC.COL_DROPDOWN_TYPE,\n");
		sbSql.append("       CTC.COL_GENE_METHOD,\n");
		sbSql.append("       CTC.COL_RULE_NAME,\n");
		sbSql.append("       CTC.COL_RULE_TITLE,\n");
		sbSql.append("       CTC.CUSTOM_PATH,\n");
		sbSql.append("       CTC.REMARK,\n");
		sbSql.append("       CTC.COL_SHOW_FORMAT,\n");
		sbSql.append("       CTC.COL_GENE_METHOD_RULE,\n");
		sbSql.append("       CTC.COL_IS_DISPLAY\n");
		sbSql.append("  FROM CBB_TAB_COLUMNS CTC\n");
		sbSql.append(" WHERE CTC.TABLE_ID = '" + tableId + "'\n");
		if ("N".equals(isAll)) {
			// 获取非系统初始字段信息
			sbSql.append(" AND CTC.COL_IS_DISPLAY = 'Y'\n");
		}
		sbSql.append(" ORDER BY CTC.COL_ORDER,CTC.COL_NAME\n");
		listDatas = jdbcAvicit.queryForMap(sbSql.toString(), null);
		// 查找节点著录定义配置信息，如果有配置信息，覆盖旧值返回

		return listDatas;
	}

	/**
	 * 根据列ID，获取列信息
	 *
	 * @author 朱锋
	 * @param colId
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbColumnsByColIdByIntfs(String colId) throws Exception {
		List<Map<String, Object>> listColumns = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CTC.ID,");
		sbSql.append("       CTC.TABLE_ID AS TID,\n");
		sbSql.append("       CTC.COL_NAME,\n");
		sbSql.append("       CTC.COL_LABEL,\n");
		sbSql.append("       CTC.COL_TYPE,\n");
		sbSql.append("       CTC.COL_LENGTH,\n");
		sbSql.append("       CTC.COL_DECIMAL,\n");
		sbSql.append("       CTC.COL_IS_SYS,\n");
		sbSql.append("       CTC.COL_ORDER,\n");
		sbSql.append("       CTC.COL_IS_MUST,\n");
		sbSql.append("       CTC.COL_IS_VISIBLE,\n");
		sbSql.append("       CTC.COL_IS_SEARCH,\n");
		sbSql.append("       CTC.COL_IS_EDIT,\n");
		sbSql.append("       CTC.COL_IS_TAB_VISIBLE,\n");
		sbSql.append("       CTC.COL_IS_DETAIL,\n");
		sbSql.append("       CTC.COL_DROPDOWN_TYPE,\n");
		sbSql.append("       CTC.COL_GENE_METHOD,\n");
		sbSql.append("       CTC.COL_RULE_NAME,\n");
		sbSql.append("       CTC.COL_RULE_TITLE,\n");
		sbSql.append("       CTC.CUSTOM_PATH,\n");
		sbSql.append("       CTC.REMARK,\n");
		sbSql.append("       CTC.COL_SHOW_FORMAT,\n");
		sbSql.append("       CTC.COL_GENE_METHOD_RULE,\n");
		sbSql.append("       CTC.COL_IS_DISPLAY,\n");
		sbSql.append("       CTC.COL_IS_COMPLEMENT,\n");
		sbSql.append("       CTC.COL_COMPLEMENT_NUM\n");
		sbSql.append("  FROM  CBB_TAB_COLUMNS CTC\n");
		sbSql.append(" WHERE CTC.ID = '" + colId + "'");
		sbSql.append(" ORDER BY CTC.COL_ORDER,CTC.COL_NAME\n");
		listColumns = jdbcAvicit.queryForMap(sbSql.toString(), null);
		// 查找节点著录定义配置信息，如果有配置信息，覆盖旧值返回

		return listColumns;
	}

	/**
	 * 根据表ID及列英文名，获取列信息
	 *
	 * @author 朱锋
	 * @param tableId
	 * @param colName
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbColumnsByTableIdAndColNameByIntfs(String tableId, String colName) throws Exception {
		colName = colName.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> listColumns = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CTC.ID,");
		sbSql.append("       CTC.TABLE_ID AS TID,\n");
		sbSql.append("       CTC.COL_NAME,\n");
		sbSql.append("       CTC.COL_LABEL,\n");
		sbSql.append("       CTC.COL_TYPE,\n");
		sbSql.append("       CTC.COL_LENGTH,\n");
		sbSql.append("       CTC.COL_DECIMAL,\n");
		sbSql.append("       CTC.COL_IS_SYS,\n");
		sbSql.append("       CTC.COL_ORDER,\n");
		sbSql.append("       CTC.COL_IS_MUST,\n");
		sbSql.append("       CTC.COL_IS_VISIBLE,\n");
		sbSql.append("       CTC.COL_IS_SEARCH,\n");
		sbSql.append("       CTC.COL_IS_EDIT,\n");
		sbSql.append("       CTC.COL_IS_TAB_VISIBLE,\n");
		sbSql.append("       CTC.COL_IS_DETAIL,\n");
		sbSql.append("       CTC.COL_DROPDOWN_TYPE,\n");
		sbSql.append("       CTC.COL_GENE_METHOD,\n");
		sbSql.append("       CTC.COL_GENE_METHOD_RULE,\n");
		sbSql.append("       CTC.COL_RULE_NAME,\n");
		sbSql.append("       CTC.COL_RULE_TITLE,\n");
		sbSql.append("       CTC.CUSTOM_PATH,\n");
		sbSql.append("       CTC.REMARK,\n");
		sbSql.append("       CTC.COL_SHOW_FORMAT,\n");
		sbSql.append("       CTC.COL_GENE_METHOD_RULE,\n");
		sbSql.append("       CTC.COL_IS_DISPLAY\n");
		sbSql.append("  FROM  CBB_TAB_COLUMNS CTC\n");
		sbSql.append(" WHERE CTC.TABLE_ID = '" + tableId + "'");
		sbSql.append(" AND CTC.COL_NAME ='" + colName + "'");
		sbSql.append(" ORDER BY CTC.COL_ORDER,CTC.COL_NAME\n");
		listColumns = jdbcAvicit.queryForMap(sbSql.toString(), null);
		// 查找节点著录定义配置信息，如果有配置信息，覆盖旧值返回

		return listColumns;
	}

	/**
	 * 根据模版代码获取模版ID
	 *
	 * @author 朱锋
	 * @param templetInfoCode
	 * @return String
	 * @throws
	 */
	@Override
	public String getTempletIdByTempletCode(String templetInfoCode) throws Exception {
		String templetId = "";
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID FROM CBB_TEMPLET_INFO T WHERE T.TEMP_CODE = '" + templetInfoCode + "'");
		List<Object> list = hibernateDao.findBySQL(sbSql.toString());
		if (list.size() > 0) {
			templetId = String.valueOf(list.get(0));
		}
		return templetId;
	}

	/**
	 * 根据表ID，获取列信息
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param tableId
	 * @param isAll
	 *            （Y：获取所有字段信息；N：设置为可见的系统字段）
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbTabColumnsByIsAllByIntfs(String orgId, String deptId, String sysId, String tableId, String isAll) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> listFields = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.*\n");
		sbSql.append("  FROM CBB_TAB_COLUMNS T\n");
		sbSql.append(" WHERE T.SYS_ID = '" + sysId + "'\n");
		sbSql.append("   AND T.TABLE_ID = '" + tableId + "'\n");
		if ("N".equals(isAll)) {
			sbSql.append("   AND T.COL_IS_DISPLAY = 'Y'\n");
		}
		sbSql.append(" ORDER BY T.COL_ORDER,T.COL_NAME");
		listFields = jdbcAvicit.queryForMap(sbSql.toString(), null);
		// 查找节点著录定义配置信息，如果有配置信息，覆盖旧值返回

		return listFields;
	}

	/*-------------------------------20150318创建方法-----------------------------------------------------*/
	/**
	 * 根据表ID，列英文名集合，获取列信息
	 *
	 * @author 朱锋
	 * @param tableId
	 * @param colNameList
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbColumnsByTableIdAndColNameListByIntfs(String tableId, List<String> colNameList) throws Exception {
		List<Map<String, Object>> listColumns = new ArrayList<Map<String, Object>>();
		if (colNameList.size() != 0) {
			StringBuffer sbSql = new StringBuffer();
			sbSql.append("SELECT CTC.ID,");
			sbSql.append("       CTC.TABLE_ID AS TID,\n");
			sbSql.append("       CTC.COL_NAME,\n");
			sbSql.append("       CTC.COL_LABEL,\n");
			sbSql.append("       CTC.COL_TYPE,\n");
			sbSql.append("       CTC.COL_LENGTH,\n");
			sbSql.append("       CTC.COL_DECIMAL,\n");
			sbSql.append("       CTC.COL_IS_SYS,\n");
			sbSql.append("       CTC.COL_ORDER,\n");
			sbSql.append("       CTC.COL_IS_MUST,\n");
			sbSql.append("       CTC.COL_IS_VISIBLE,\n");
			sbSql.append("       CTC.COL_IS_SEARCH,\n");
			sbSql.append("       CTC.COL_IS_EDIT,\n");
			sbSql.append("       CTC.COL_IS_TAB_VISIBLE,\n");
			sbSql.append("       CTC.COL_IS_DETAIL,\n");
			sbSql.append("       CTC.COL_DROPDOWN_TYPE,\n");
			sbSql.append("       CTC.COL_GENE_METHOD,\n");
			sbSql.append("       CTC.COL_RULE_NAME,\n");
			sbSql.append("       CTC.COL_RULE_TITLE,\n");
			sbSql.append("       CTC.CUSTOM_PATH,\n");
			sbSql.append("       CTC.REMARK,\n");
			sbSql.append("       CTC.COL_SHOW_FORMAT,\n");
			sbSql.append("       CTC.COL_GENE_METHOD_RULE,\n");
			sbSql.append("       CTC.COL_IS_DISPLAY\n");
			sbSql.append("  FROM  CBB_TAB_COLUMNS CTC\n");
			sbSql.append(" WHERE 1=1 AND (\n");
			for (int i = 0; i < colNameList.size(); i++) {
				String colName = colNameList.get(i);
				if (i == 0) {
					sbSql.append(" CTC.COL_NAME ='" + colName + "'");
				} else {
					sbSql.append(" OR CTC.COL_NAME ='" + colName + "'");
				}
			}
			sbSql.append(") AND CTC.TABLE_ID = '" + tableId + "'");
			sbSql.append(" ORDER BY CTC.COL_ORDER,CTC.COL_NAME\n");
			listColumns = jdbcAvicit.queryForMap(sbSql.toString(), null);
		}
		return listColumns;
	}

	/*---------------------------------------------------自建实现类方法--------------------------------------------------------------*/
	/**
	 * 根据CbbTablesId获取该表对象
	 *
	 * @author 朱锋
	 * @param id
	 * @return CbbTables
	 * @throws
	 */
	public CbbTables getCbbTablesById(String id) {
		CbbTables h = (CbbTables) hibernateDao.getSession().get(CbbTables.class, id);
		return h;
	}

	/**
	 * 获取已经存在的表名数量
	 *
	 * @author 朱锋
	 * @param textpinyin
	 * @return int
	 * @throws
	 */
	public int getSumTableCount(String textpinyin) {
		int num = 0;
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT COUNT(*) FROM CBB_TABLES T WHERE T.TABLE_NAME LIKE '" + textpinyin + "'");
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		if (objList.size() > 0) {
			num = Integer.parseInt(String.valueOf(objList.get(0)));
		}
		return num;
	}

	/**
	 * 向CBB_TABLES插入记录
	 *
	 * @author 朱锋
	 * @param tid
	 * @param tableName
	 * @param tableTitle
	 * @param sysId
	 *            void
	 * @throws
	 */
	public void insertCbbTables(String tid, String tableName, String tableTitle, String orgId, String deptId, String sysId, String loginUserId, String loginIp, String isTrueTable) {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		tableName = tableName.toUpperCase(); // 将参数转换为大写
		StringBuffer sbSql = new StringBuffer();
		try {
			sbSql.append("INSERT INTO CBB_TABLES\n" + "VALUES\n" + "  ('");
			sbSql.append(tid + "',\n" + "   '" + tableName + "',\n" + "   '");
			sbSql.append(tableTitle);
			sbSql.append("',\n");
			sbSql.append("   'Y',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '");
			sbSql.append(orgId);
			sbSql.append("',\n");
			sbSql.append("   '");
			sbSql.append(deptId);
			sbSql.append("',\n");
			sbSql.append("   '");
			sbSql.append(sysId);
			sbSql.append("',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   SYSDATE,\n");
			sbSql.append("   '");
			sbSql.append(loginUserId);
			sbSql.append("',\n");
			sbSql.append("   SYSDATE,\n");
			sbSql.append("   '");
			sbSql.append(loginUserId);
			sbSql.append("',\n");
			sbSql.append("   '");
			sbSql.append(loginIp);
			sbSql.append("',\n");
			sbSql.append("   1,\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '" + isTrueTable + "')");
			jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
			jdbcAvicit.getJdbcTemplate().execute("commit");
			SysLogUtil.log("库结构定义模块", "新增表记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 根据tableId获取ColumnsIds集合
	 *
	 * @author 朱锋
	 * @param tableId
	 * @return List<Object>
	 * @throws
	 */
	public List<Object> getColumnsIdByTableId(String tableId) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID = '" + tableId + "'");
		List<Object> list = hibernateDao.findBySQL(sbSql.toString());
		return list;
	}

	/**
	 * 根据ColumnsId获取该表对象
	 *
	 * @author 朱锋
	 * @param id
	 * @return CbbTabColumns
	 * @throws
	 */
	public CbbTabColumns getCbbTabColumnsById(String id) {
		CbbTabColumns h = (CbbTabColumns) hibernateDao.getSession().get(CbbTabColumns.class, id);
		return h;
	}

	/**
	 * cbbTabColumns该tableId下的最大排序值
	 *
	 * @author 朱锋
	 * @param tid
	 * @return int
	 * @throws
	 */
	public int selectMaxOrder(String tableId) {
		int num = 0;
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT MAX(T.COL_ORDER) FROM CBB_TAB_COLUMNS T WHERE T.TABLE_ID = '" + tableId + "'");
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		for (int i = 0; i < objList.size(); i++) {
			if (!"null".equals(String.valueOf(objList.get(i)))) {
				num = Integer.parseInt(String.valueOf(objList.get(i)));
			}
		}
		return num;
	}

	/**
	 * cbbTabColumns该tid下的列最大表格排序值
	 *
	 * @author 朱锋
	 * @param tid
	 * @return int
	 * @throws
	 */
	public int selectMaxTabOrder(String tid) {
		int num = 0;
		String sql = "select max(t.ATTRIBUTE_11) from CBB_TAB_COLUMNS t where t.table_id = '" + tid + "'";
		List<Object> objList = hibernateDao.findBySQL(sql);
		for (int i = 0; i < objList.size(); i++) {
			if (!"null".equals(String.valueOf(objList.get(i))) && !"".equals(String.valueOf(objList.get(i)))) {
				num = Integer.parseInt(String.valueOf(objList.get(i)));
			}
		}
		return num;
	}

	/**
	 * 向CBB_TAB_COLUMNS插入记录
	 *
	 * @author 朱锋
	 * @param cbbTabColumns
	 * @param cid
	 * @param tid
	 * @param colOrder
	 * @param sysId
	 *            void
	 * @throws
	 */
	public String insertCbbTabColumus(CbbTabColumns cbbTabColumns, String tid, String orgId, String deptId, String sysId, String loginUserId, String loginIp) {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		String colId = ComUtil.getId();
		StringBuffer sbSql = new StringBuffer();
		try {
			sbSql.append("INSERT INTO CBB_TAB_COLUMNS\n" + "VALUES\n");
			sbSql.append("  ('");
			sbSql.append(colId);
			sbSql.append("',\n");
			sbSql.append("   '");
			sbSql.append(tid);
			sbSql.append("',\n");
			sbSql.append("   '");
			sbSql.append(cbbTabColumns.getColName());
			sbSql.append("',\n");
			sbSql.append("   '");
			sbSql.append(cbbTabColumns.getColLabel());
			sbSql.append("',\n");
			sbSql.append("   '");
			sbSql.append(cbbTabColumns.getColType());
			sbSql.append("',\n");
			sbSql.append("   ");
			sbSql.append(cbbTabColumns.getColLength());
			sbSql.append(",\n");
			sbSql.append("   ");
			sbSql.append(cbbTabColumns.getColDecimal());
			sbSql.append(",\n");
			sbSql.append("   '" + cbbTabColumns.getColIsSys() + "',\n");
			sbSql.append("   ");
			sbSql.append(cbbTabColumns.getColOrder());
			sbSql.append(",\n");
			sbSql.append("   '" + cbbTabColumns.getColIsMust() + "',\n");
			sbSql.append("   '" + cbbTabColumns.getColIsVisible() + "',\n");
			sbSql.append("   '" + cbbTabColumns.getColIsSearch() + "',\n");
			sbSql.append("   '" + cbbTabColumns.getColIsEdit() + "',\n");
			sbSql.append("   '" + cbbTabColumns.getColIsTabVisible() + "',\n");
			sbSql.append("   '" + cbbTabColumns.getColIsDetail() + "',\n");
			sbSql.append("   '" + cbbTabColumns.getColDropdownType() + "',\n");
			sbSql.append("   '" + cbbTabColumns.getColGeneMethod() + "',\n");
			if (!"null".equals(cbbTabColumns.getColRuleName()) && null != cbbTabColumns.getColRuleName()) {
				sbSql.append("   '" + cbbTabColumns.getColRuleName() + "',\n");
			} else {
				sbSql.append("   '',\n");
			}
			if (!"null".equals(cbbTabColumns.getColRuleTitle()) && null != cbbTabColumns.getColRuleTitle()) {
				sbSql.append("   '" + cbbTabColumns.getColRuleTitle() + "',\n");
			} else {
				sbSql.append("   '',\n");
			}
			if (!"null".equals(cbbTabColumns.getCustomPath()) && null != cbbTabColumns.getCustomPath()) {
				sbSql.append("   '" + cbbTabColumns.getCustomPath() + "',\n");
			} else {
				sbSql.append("   '',\n");
			}
			if (!"null".equals(cbbTabColumns.getRemark()) && null != cbbTabColumns.getRemark()) {
				sbSql.append("   '" + cbbTabColumns.getRemark() + "',\n");
			} else {
				sbSql.append("   '',\n");
			}
			sbSql.append("   '");
			sbSql.append(orgId);
			sbSql.append("',\n");
			sbSql.append("   '");
			sbSql.append(deptId);
			sbSql.append("',\n");
			sbSql.append("   '");
			sbSql.append(sysId);
			sbSql.append("',\n");
			sbSql.append("   '',\n");
			sbSql.append("   '',\n");
			sbSql.append("   SYSDATE,\n");
			sbSql.append("   '");
			sbSql.append(loginUserId);
			sbSql.append("',\n");
			sbSql.append("   SYSDATE,\n");
			sbSql.append("   '");
			sbSql.append(loginUserId);
			sbSql.append("',\n");
			sbSql.append("   '");
			sbSql.append(loginIp);
			sbSql.append("',\n");
			sbSql.append(" 1,\n");
			sbSql.append(" '',\n");
			sbSql.append(" '',\n");
			sbSql.append(" '',\n");
			sbSql.append(" '',\n");
			sbSql.append(" '',\n");
			sbSql.append(" '',\n");
			sbSql.append(" '',\n");
			sbSql.append(" '',\n");
			sbSql.append(" '',\n");
			sbSql.append(" '',\n");
			sbSql.append(" " + cbbTabColumns.getAttribute11() + " ,\n");
			sbSql.append(" '',\n");
			sbSql.append(" '' ,\n");
			sbSql.append(" '' ,\n");
			sbSql.append(" '' ,\n");
			if (!"null".equals(cbbTabColumns.getColShowFormat()) && null != cbbTabColumns.getColShowFormat()) {
				sbSql.append("  '" + cbbTabColumns.getColShowFormat() + "',\n");
			} else {
				sbSql.append("  '0',\n");
			}
			if (!"null".equals(cbbTabColumns.getColGeneMethodRule()) && null != cbbTabColumns.getColGeneMethodRule()) {
				sbSql.append(" '" + cbbTabColumns.getColGeneMethodRule() + "',\n");
			} else {
				sbSql.append(" '',\n");
			}
			sbSql.append(" '" + cbbTabColumns.getColIsDisplay() + "',");
			sbSql.append(" '" + cbbTabColumns.getColIsComplement() + "',");// 是否补足
			sbSql.append(cbbTabColumns.getColComplementNum() + ",");// 补足位数
			if (!"null".equals(cbbTabColumns.getColGeneMethodRuleText()) && null != cbbTabColumns.getColGeneMethodRuleText()) {
				sbSql.append(" '" + cbbTabColumns.getColGeneMethodRuleText() + "')\n");
			} else {
				sbSql.append("'')");// 生成方式中文名称
			}
			jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
			jdbcAvicit.getJdbcTemplate().execute("commit");
			SysLogUtil.log("库结构定义模块", "新增列记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return colId;
	}

	/**
	 * CBB_TAB_NODE该TABLE_ID,NODE_ID,SYS_ID下的最大排序值
	 *
	 * @author 朱锋
	 * @param nodeId
	 * @param sysId
	 * @return int
	 * @throws
	 */
	public int selectMaxSort(String nodeId, String sysId) {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		int num = 0;
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT MAX(T.TAB_ORDER)\n");
		sbSql.append("  FROM CBB_TAB_NODE T\n");
		sbSql.append(" WHERE T.NODE_ID = '" + nodeId + "'\n");
		sbSql.append("   AND T.SYS_ID = '" + sysId + "'");
		List<Object> objList = hibernateDao.findBySQL(sbSql.toString());
		for (int i = 0; i < objList.size(); i++) {
			if (!"null".equals(String.valueOf(objList.get(i)))) {
				num = Integer.parseInt(String.valueOf(objList.get(i)));
			}
		}
		return num;
	}

	/**
	 * 生成动态表
	 *
	 * @author 朱锋
	 * @param tableId
	 * @param sysId
	 * @throws DaoException
	 *             void
	 * @throws
	 */
	public void insertdbTable(String tableId, String sysId, String orgId) throws DaoException {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		ArrayList<Object> params = new ArrayList<Object>();
		try {
			// 查询表名，表注释
			CbbTables cbbTables = getCbbTablesById(tableId);
			String tableName = cbbTables.getTableName();// 表名
			String tableTitle = cbbTables.getTableTitle();// 表注释
			String templetId = getCbbTempletInfoIdBySysId(sysId.toUpperCase(), orgId);// templetId
			// 查询SYSID及组织ID，获取所对应的用户名
			List<Map<String,Object>> listConn = this.cbbFondsDbIntfsService.getCbbFondsDbInfoByIntfs(orgId, "", sysId,"");
			String dbUser = "";//用户名
			if(listConn.size() > 0){
				Map<String,Object> connmap = listConn.get(0);
				dbUser = String.valueOf(connmap.get("DB_USER"));
			}else{
				throw new DaoException("创建动态表是出错！当前全宗数据库未配置！");
			}
			params.add(0, tableName);
			params.add(1, tableTitle);
			params.add(2, tableId);
			params.add(3, templetId);
			params.add(4, dbUser);
			commTableManagerDao.callProcedure("CBB_TABLEDEFINE_P.CREATE_TEMP_TABLE", params);
			SysLogUtil.log("库结构定义模块", "新增实体表记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
		} catch (Exception e) {
			e.printStackTrace();
			throw new DaoException("创建动态表是出错！");
		}
	}

	/**
	 * 根据sysId查询templetId
	 *
	 * @author 朱锋
	 * @param sysId
	 * @return List<Object>
	 * @throws
	 */
	public String getCbbTempletInfoIdBySysId(String sysId, String orgId) {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID\n");
		sbSql.append("  FROM CBB_TEMPLET_INFO T\n");
		sbSql.append(" WHERE T.TEMP_TYPE = 'S'\n");
		sbSql.append("   AND T.SYS_ID = '" + sysId + "'\n");
		// sbSql.append("   AND (T.ORG_ID = '" + orgId + "' OR T.ORG_ID = 'ORG_ROOT')");
		List<Object> list = hibernateDao.findBySQL(sbSql.toString());
		String templetId = "";
		if (list.size() > 0) {
			templetId = String.valueOf(list.get(0));
		}
		return templetId;
	}

	/**
	 * 根据templetCode查询templetId
	 *
	 * @author 朱锋
	 * @param sysId
	 * @return List<Object>
	 * @throws
	 */
	public String getCbbTempletInfoIdByTempletCode(String sysId, String orgId, String templetCode) {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID\n");
		sbSql.append("  FROM CBB_TEMPLET_INFO T\n");
		sbSql.append(" WHERE T.TEMP_TYPE = 'C'\n");
		sbSql.append("   AND T.SYS_ID = '" + sysId + "'\n");
		sbSql.append("   AND T.ORG_ID = '" + orgId + "'");
		sbSql.append("   AND T.TEMP_CODE = '" + templetCode + "'");
		List<Object> list = hibernateDao.findBySQL(sbSql.toString());
		String templetId = "";
		if (list.size() > 0) {
			templetId = String.valueOf(list.get(0));
		}
		return templetId;
	}

	/**
	 * 查询SYSID所对应的用户名
	 *
	 * @author 朱锋
	 * @param id
	 * @return String
	 * @throws
	 */
	public String getDbUserById(String id) {
		try {
			StringBuffer sbSql = new StringBuffer();
			sbSql.append("SELECT T.DB_USER FROM CBB_FONDS_DB T WHERE T.SYS_ID = '" + id.toUpperCase() + "'");
			List<Object> lists = hibernateDao.findBySQL(sbSql.toString());
			String dbUser = "";// 用户名
			if (lists.size() > 0) {
				dbUser = String.valueOf(lists.get(0));// dbuser
			}
			return dbUser;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 根据参数创建库表
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tableTitle
	 * @param tableNameFix
	 * @param loginUserId
	 * @param loginIp
	 * @param ifTrue
	 * @param nodeCode
	 * @param param
	 * 				key:TAB_FLAG value:string (结构类型 0：案卷级，1：盒级)
	 * @throws Exception
	 *             void
	 * @throws
	 */
	public void createTabForm(String orgId, String deptId, String sysId, String nodeId, String nodeName, String tableTitle, String tableNameFix, String loginUserId, String loginIp, boolean ifTrue, String nodeCode, Map<String, Object> param) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		if (!param.containsKey("TAB_FLAG")) {
			throw new Exception("调用方法时TAB_FLAG参数不存在，请检查！");
		}
		String tabFlag = String.valueOf(param.get("TAB_FLAG"));
		if (null == tabFlag || "".equals(tabFlag) || "null".equals(tabFlag)) {
			throw new Exception("调用方法时TAB_FLAG参数不存在，请检查！");
		}
		// 1.向CBB_TABLES插入记录
		CbbTables cbbTables = new CbbTables();
		String tableId = ComUtil.getId();
		cbbTables.setId(tableId);
		String tableName = "";
		// 判断是否为真实表
		String isTrueTable = "";
		if (ifTrue) {
			tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
			boolean hasOne = false;// 初始化是否存在表名
			// 查询是否有初始化表名
			if (getSumTableCount(tableName) != 0) {
				hasOne = true;
			}
			if (hasOne) {
				tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + "_%" + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
				int num = getSumTableCount(tableName);
				tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + "_" + (num + 1) + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
				//sanxiaFiles create by wuliang 2019.11.1   start 关系表表明唯一校验
				while (getSumTableCount(tableName) != 0) {
						num++;
						tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + "_" + num + tableNameFix.toUpperCase();
				}
				//sanxiaFiles create by wuliang 2019.11.1   end 关系表表明唯一校验

				while (true) {
					// 判断数据库是否存在此表
					String hastabSql = "SELECT COUNT(*) FROM ALL_TABLES W WHERE W.TABLE_NAME = '" + tableName + "'";
					List<Object> hastabList = this.hibernateDao.findBySQL(hastabSql);
					if (String.valueOf(hastabList.get(0)).equals("0")) {
						break;
					} else {
						num++;
						tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + "_" + (num + 1) + tableNameFix.toUpperCase();
					}
				}
				tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + "_" + num + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
			} else {
				tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
			}
			isTrueTable = "Y";
		} else {
			tableName = nodeCode;
			isTrueTable = "N";
		}
		insertCbbTables(tableId, tableName, tableTitle, orgId, deptId, sysId, loginUserId, loginIp, isTrueTable);
		if (ifTrue) { // 如果为真实表
			// 2.向CBB_TAB_COLUMNS插入记录(取系统初始化字段信息)
			List<Map<String, Object>> listField = new ArrayList<Map<String, Object>>();// 初始化字段集合
			String templetId = getCbbTempletInfoIdBySysId(sysId.toUpperCase(), orgId);// templetId
			StringBuffer sbSql = new StringBuffer();
			sbSql.append("SELECT *\n");
			sbSql.append("  FROM CBB_TEMPLET_FIELD T\n");
			sbSql.append(" WHERE T.ID IN (SELECT MAX(ID)\n");
			sbSql.append("                  FROM CBB_TEMPLET_FIELD C\n");
			sbSql.append("                 WHERE C.TEMPLET_ID = '" + templetId + "'\n");
			if (param.containsKey("templetModelId")) {
				String templetModelId = (String) param.get("templetModelId");
				String[] ids = templetModelId.split(",");
				for (int i = 0; i < ids.length; i++) {
					sbSql.append("                    OR C.TEMPLET_ID = '" + ids[i] + "'\n");
				}
			}
			sbSql.append("                 GROUP BY C.COL_NAME)\n");
			sbSql.append(" ORDER BY T.COL_ORDER, T.COL_NAME");
			listField = jdbcAvicit.queryForMap(sbSql.toString(), null);
			for (int i = 0; i < listField.size(); i++) {
				CbbTabColumns cbbTabColumns = new CbbTabColumns();
				Map<String, Object> map = listField.get(i);
				String fieldId = String.valueOf(map.get("ID"));
				cbbTabColumns.setColName(String.valueOf(map.get("COL_NAME")));
				cbbTabColumns.setColLabel(String.valueOf(map.get("COL_LABEL")));
				cbbTabColumns.setColType(String.valueOf(map.get("COL_TYPE")));
				if (map.get("COL_LENGTH") != null) {
					int length = Integer.parseInt(String.valueOf(map.get("COL_LENGTH")));
					BigDecimal colLength = new BigDecimal(length);
					cbbTabColumns.setColLength(colLength);
				}
				if (map.get("COL_DECIMAL") != null) {
					int decimal = Integer.parseInt(String.valueOf(map.get("COL_DECIMAL")));
					BigDecimal colDecimal = new BigDecimal(decimal);
					cbbTabColumns.setColDecimal(colDecimal);
				}
				cbbTabColumns.setColIsSys("Y");
				int numorder = Integer.parseInt(String.valueOf(map.get("COL_ORDER")));
				BigDecimal colOrder = new BigDecimal(numorder);
				cbbTabColumns.setColOrder(colOrder);
				int numtab = Integer.parseInt(String.valueOf(map.get("ATTRIBUTE_11")));
				BigDecimal colTabOrder = new BigDecimal(numtab);
				cbbTabColumns.setAttribute11(colTabOrder);
				cbbTabColumns.setColIsMust(String.valueOf(map.get("COL_IS_MUST")));
				cbbTabColumns.setColIsVisible(String.valueOf(map.get("COL_IS_VISIBLE")));
				cbbTabColumns.setColIsSearch(String.valueOf(map.get("COL_IS_SEARCH")));
				cbbTabColumns.setColIsEdit(String.valueOf(map.get("COL_IS_EDIT")));
				cbbTabColumns.setColIsTabVisible(String.valueOf(map.get("COL_IS_TAB_VISIBLE")));
				cbbTabColumns.setColIsDetail(String.valueOf(map.get("COL_IS_DETAIL")));
				cbbTabColumns.setColDropdownType(String.valueOf(map.get("COL_DROPDOWN_TYPE")));
				cbbTabColumns.setColGeneMethod(String.valueOf(map.get("COL_GENE_METHOD")));
				cbbTabColumns.setColRuleName(String.valueOf(map.get("COL_RULE_NAME")));
				cbbTabColumns.setColRuleTitle(String.valueOf(map.get("COL_RULE_TITLE")));
				cbbTabColumns.setCustomPath(String.valueOf(map.get("CUSTOM_PATH")));
				cbbTabColumns.setRemark(String.valueOf(map.get("REMARK")));
				cbbTabColumns.setColGeneMethodRule("");
				cbbTabColumns.setColIsDisplay(String.valueOf(map.get("COL_IS_DISPLAY")));
				cbbTabColumns.setColShowFormat("0");
				cbbTabColumns.setColIsComplement("N");
				String columnId = insertCbbTabColumus(cbbTabColumns, tableId, orgId, deptId, sysId, loginUserId, loginIp);

				/*****************复制列多语言信息****************************/
				CbbTabColumnsTlDTO cbbTabColumnsTlDTO = new CbbTabColumnsTlDTO();
				List<Map<String, Object>> list = cbbTabColumnsTlService.findSysLanguageByParentId2(fieldId);
				for (int i1 = 0; i1 < list.size(); i1++) {
					String sysLanguageCode = list.get(i1).get("SYS_LANGUAGE_CODE").toString();// 语言代码
					String columnsShowName = list.get(i1).get("COLUMNS_SHOW_NAME").toString();// 列显示名称
					String description = list.get(i1).get("DESCRIPTION") == null ? "" : list.get(i1).get("DESCRIPTION").toString();// 描述

					cbbTabColumnsTlDTO.setSysLanguageCode(sysLanguageCode);
					cbbTabColumnsTlDTO.setCbbTabColumnsId(columnId);
					cbbTabColumnsTlDTO.setColumnsShowName(columnsShowName);
					cbbTabColumnsTlDTO.setDescription(description);
					cbbTabColumnsTlService.insertCbbTabColumnsTl(cbbTabColumnsTlDTO);

				}

				// 添加通用代码（取系统初始化字段信息）
				// 复制通用代码信息（CBB_TEMPLET_SYS_CODE表）
				String codeSql = "SELECT T.SYS_LOOKUP_ID,T.REMARK FROM CBB_TEMPLET_SYS_CODE T WHERE T.FIELD_ID = '" + fieldId + "'";
				List<Object[]> codeList = this.hibernateDao.findBySQL(codeSql);
				if (codeList != null && codeList.size() > 0) {
					CbbTabColSysCode cbbTabColSysCode = new CbbTabColSysCode();
					cbbTabColSysCode.setSysLookupId(codeList.get(0)[0].toString());
					cbbTabColSysCode.setRemark(codeList.get(0)[1] == null ? "" : codeList.get(0)[1].toString());
					String id = ComUtil.getId();
					cbbTabColSysCode.setId(id);
					cbbTabColSysCode.setTableId(tableId);
					cbbTabColSysCode.setColumnId(columnId);
					cbbTabColSysCode.setOrgId(orgId);
					cbbTabColSysCode.setDeptId(deptId);
					cbbTabColSysCode.setSysId(sysId);
					PojoUtil.setSysProperties(cbbTabColSysCode, OpType.insert);
					hibernateDao.save(cbbTabColSysCode);
					SysLogUtil.log(cbbTabColSysCode, null, OpType.insert, OpResult.success);
				}
				// 复制通用代码信息（CBB_TEMPLET_CODE表）
				String codeSql2 = "SELECT T.CODE_ORDER,T.CODE_IS_VALID,T.LOOKUP_NAME,T.LOOKUP_CODE,T.REMARK,T.ID FROM CBB_TEMPLET_CODE T WHERE T.FIELD_ID = '" + fieldId + "'";
				List<Object[]> codeList2 = this.hibernateDao.findBySQL(codeSql2);
				for (int j = 0; j < codeList2.size(); j++) {
					CbbTabColCode cbbTabColCode = new CbbTabColCode();
					cbbTabColCode.setCodeOrder(new BigDecimal(codeList2.get(j)[0].toString()));
					cbbTabColCode.setCodeIsValid(codeList2.get(j)[1].toString());
					cbbTabColCode.setLookupName(codeList2.get(j)[2].toString());
					cbbTabColCode.setLookupCode(codeList2.get(j)[3].toString());
					cbbTabColCode.setRemark(codeList2.get(j)[4] == null ? "" : codeList2.get(j)[4].toString());
					String id = ComUtil.getId();
					cbbTabColCode.setId(id);
					cbbTabColCode.setTableId(tableId);
					cbbTabColCode.setColumnId(columnId);
					cbbTabColCode.setDeptId(deptId);
					cbbTabColCode.setOrgId(orgId);
					cbbTabColCode.setSysId(sysId);
					PojoUtil.setSysProperties(cbbTabColCode, OpType.insert);
					hibernateDao.save(cbbTabColCode);
					SysLogUtil.log(cbbTabColCode, null, OpType.insert, OpResult.success);
					/*****************复制通用代码（CBB_TEMPLET_CODE表）多语言信息****************************/
					String codeSqlLanguange = "SELECT T.SYS_LANGUAGE_CODE,T.COLUMNS_SHOW_NAME,T.DESCRIPTION,T.ID FROM CBB_TEMPLET_CODE_TL T WHERE  T.CBB_TEMPLET_CODE_ID = '" + codeList2.get(j)[5].toString() + "'";
					List<Object[]> LanguangeCodeList2 = this.hibernateDao.findBySQL(codeSqlLanguange);
					for (int i2 = 0; i2 < LanguangeCodeList2.size(); i2++) {
						CbbTabColCodeTlDTO cbbTabColCodeTlDTO = new CbbTabColCodeTlDTO();
						cbbTabColCodeTlDTO.setCbbTabColCodeId(cbbTabColCode.getId());
						cbbTabColCodeTlDTO.setSysLanguageCode(LanguangeCodeList2.get(i2)[0].toString());
						cbbTabColCodeTlDTO.setColumnsShowName(LanguangeCodeList2.get(i2)[1].toString());
						cbbTabColCodeTlDTO.setDescription(LanguangeCodeList2.get(i2)[2] == null ? "" : LanguangeCodeList2.get(i2)[2].toString());
						cbbTabColCodeTlService.insertCbbTabColCodeTl(cbbTabColCodeTlDTO);

					}

				}
			}
		}
		// 3.向CBB_TAB_NODE插入记录
		Map<String, Object> param2 = new HashMap<String, Object>();
		param2.put("TAB_FLAG", tabFlag);
		createCbbTabNodeByIntfs(orgId, deptId, sysId, nodeId, tableId, loginUserId, loginIp, param2);
		if (ifTrue) { // 如果为真实表
			// 4.调用创建实体表存储过程
			insertdbTable(tableId, sysId, orgId);
			// 5.调用表单接口，新增表单相关信息
			billDefineManagerIntfsService.createCbbTabFormByIntfs(orgId, deptId, sysId, nodeId, nodeName, tableId);
		}

	}

	/**
	 * 根据参数创建技术资料动态管理库表
	 *
	 * @author 朱锋
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param nodeName
	 * @param tableTitle
	 * @param tableNameFix
	 * @param loginUserId
	 * @param loginIp
	 * @param nodeCode
	 * @throws Exception
	 *             void
	 * @throws
	 */
	public void createTabFormBytech(String orgId, String deptId, String sysId, String nodeId, String nodeName, String tableTitle, String tableNameFix, String loginUserId, String loginIp, String nodeCode, Map<String, Object> param) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		// 1.获取基本表文件级表名
		String tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
		boolean hasOne = false;// 初始化是否存在表名
		// 查询是否有初始化表名
		if (getSumTableCount(tableName) != 0) {
			hasOne = true;
		}
		if (hasOne) {
			tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + "_%" + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
			int num = getSumTableCount(tableName);
			tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + "_" + (num + 1) + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
			while (true) {
				// 判断数据库是否存在此表
				String hastabSql = "SELECT COUNT(*) FROM ALL_TABLES W WHERE W.TABLE_NAME = '" + tableName + "'";
				List<Object> hastabList = this.hibernateDao.findBySQL(hastabSql);
				if (String.valueOf(hastabList.get(0)).equals("0")) {
					break;
				} else {
					num++;
				}
			}
			tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + "_" + num + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
		} else {
			tableName = sysId + "_" + Pinyin4jUtil.getPinYinHeadChar(nodeCode).toUpperCase() + tableNameFix.toUpperCase();// 根据分类树名称转换为拼音首字母
		}
		tableName = tableName + "_TE";
		// 2.读取技术资料动态管理模版八张库表
		// 第一张：二次下发表
		createTech(sysId, orgId, "ECXF", deptId, loginUserId, loginIp, "二次下发", tableName, tableTitle, "2", nodeId, nodeName);
		// 第二张：代替关系表
		createTech(sysId, orgId, "DTGX", deptId, loginUserId, loginIp, "代替关系", tableName, tableTitle, "2", nodeId, nodeName);
		// 第三张：分发单表
		createTech(sysId, orgId, "FFD", deptId, loginUserId, loginIp, "分发单", tableName, tableTitle, "2", nodeId, nodeName);
		// 第四张：分发单与技术资料关系表
		createTech(sysId, orgId, "RFFD", deptId, loginUserId, loginIp, "分发单与技术资料关系", tableName, tableTitle, "2", nodeId, nodeName);
		// 第五张：分发路线表
		createTech(sysId, orgId, "FFLX", deptId, loginUserId, loginIp, "分发路线", tableName, tableTitle, "2", nodeId, nodeName);
		// 第六张：回收单表
		createTech(sysId, orgId, "HSD", deptId, loginUserId, loginIp, "回收单", tableName, tableTitle, "2", nodeId, nodeName);
		// 第七张：回收单与技术资料关系表
		createTech(sysId, orgId, "RHSD", deptId, loginUserId, loginIp, "回收单与技术资料关系", tableName, tableTitle, "2", nodeId, nodeName);
		// 第八张：更改关系表
		createTech(sysId, orgId, "GGGX", deptId, loginUserId, loginIp, "更改关系", tableName, tableTitle, "2", nodeId, nodeName);
	}

	/**
	 * 根据模版CODE创建库表
	 * @param sysId
	 * @param orgId
	 * @param templetCode
	 * @param deptId
	 * @param loginUserId
	 * @param loginIp
	 * @param templetName
	 * @param tableId
	 * @param tableName
	 * @param tableTitle
	 * @param tabFlag
	 * @param nodeId
	 * @param nodeName
	 * @throws Exception void
	 * @throws
	 */
	public void createTech(String sysId, String orgId, String templetCode, String deptId, String loginUserId, String loginIp, String templetName, String tableName, String tableTitle, String tabFlag, String nodeId, String nodeName) throws Exception {
		String techTempletId = getCbbTempletInfoIdByTempletCode(sysId, orgId, templetCode);// 获取二次下发模版主ID
		String tableId = ComUtil.getId();
		insertCbbTables(tableId, tableName + "_" + templetCode, tableTitle + "_" + templetName, orgId, deptId, sysId, loginUserId, loginIp, "Y");
		// 2.向CBB_TAB_COLUMNS插入记录(取系统初始化字段信息)
		List<Map<String, Object>> listtechField = new ArrayList<Map<String, Object>>();// 字段集合
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT * FROM CBB_TEMPLET_FIELD C WHERE C.TEMPLET_ID = '" + techTempletId + "' ORDER BY C.COL_ORDER,C.COL_NAME");
		listtechField = jdbcAvicit.queryForMap(sbSql.toString(), null);
		for (int i = 0; i < listtechField.size(); i++) {
			CbbTabColumns cbbTabColumns = new CbbTabColumns();
			Map<String, Object> map = listtechField.get(i);
			String fieldId = String.valueOf(map.get("ID"));
			cbbTabColumns.setColName(String.valueOf(map.get("COL_NAME")));
			cbbTabColumns.setColLabel(String.valueOf(map.get("COL_LABEL")));
			cbbTabColumns.setColType(String.valueOf(map.get("COL_TYPE")));
			if (map.get("COL_LENGTH") != null) {
				int length = Integer.parseInt(String.valueOf(map.get("COL_LENGTH")));
				BigDecimal colLength = new BigDecimal(length);
				cbbTabColumns.setColLength(colLength);
			}
			if (map.get("COL_DECIMAL") != null) {
				int decimal = Integer.parseInt(String.valueOf(map.get("COL_DECIMAL")));
				BigDecimal colDecimal = new BigDecimal(decimal);
				cbbTabColumns.setColDecimal(colDecimal);
			}
			cbbTabColumns.setColIsSys("Y");
			// 取cbbTabColumns该tableId下的最大排序值
			int num = selectMaxOrder(tableId) + 1;
			BigDecimal colOrder = new BigDecimal(num);
			cbbTabColumns.setColOrder(colOrder);
			// 取cbbTabColumns该tableId下的表格最大排序值
			int numTab = selectMaxOrder(tableId) + 1;
			BigDecimal colTabOrder = new BigDecimal(numTab);
			cbbTabColumns.setAttribute11(colTabOrder);
			cbbTabColumns.setColIsMust(String.valueOf(map.get("COL_IS_MUST")));
			cbbTabColumns.setColIsVisible(String.valueOf(map.get("COL_IS_VISIBLE")));
			cbbTabColumns.setColIsSearch(String.valueOf(map.get("COL_IS_SEARCH")));
			cbbTabColumns.setColIsEdit(String.valueOf(map.get("COL_IS_EDIT")));
			cbbTabColumns.setColIsTabVisible(String.valueOf(map.get("COL_IS_TAB_VISIBLE")));
			cbbTabColumns.setColIsDetail(String.valueOf(map.get("COL_IS_DETAIL")));
			cbbTabColumns.setColDropdownType(String.valueOf(map.get("COL_DROPDOWN_TYPE")));
			cbbTabColumns.setColGeneMethod(String.valueOf(map.get("COL_GENE_METHOD")));
			cbbTabColumns.setColRuleName(String.valueOf(map.get("COL_RULE_NAME")));
			cbbTabColumns.setColRuleTitle(String.valueOf(map.get("COL_RULE_TITLE")));
			cbbTabColumns.setCustomPath(String.valueOf(map.get("CUSTOM_PATH")));
			cbbTabColumns.setRemark(String.valueOf(map.get("REMARK")));
			cbbTabColumns.setColGeneMethodRule("");
			cbbTabColumns.setColIsDisplay(String.valueOf(map.get("COL_IS_DISPLAY")));
			cbbTabColumns.setColShowFormat("0");
			cbbTabColumns.setColIsComplement("N");
			String columnId = insertCbbTabColumus(cbbTabColumns, tableId, orgId, deptId, sysId, loginUserId, loginIp);
			/****************** 复制列多语言信息******************/
			CbbTabColumnsTlDTO cbbTabColumnsTlDTO = new CbbTabColumnsTlDTO();
			List<Map<String, Object>> list = cbbTabColumnsTlService.findSysLanguageByParentId2(fieldId);
			for (int i1 = 0; i1 < list.size(); i1++) {
				String sysLanguageCode = list.get(i1).get("SYS_LANGUAGE_CODE").toString();// 语言代码
				String columnsShowName = list.get(i1).get("COLUMNS_SHOW_NAME").toString();// 列显示名称
				String description = list.get(i1).get("DESCRIPTION") == null ? "" : list.get(i1).get("DESCRIPTION").toString();// 描述
				cbbTabColumnsTlDTO.setSysLanguageCode(sysLanguageCode);
				cbbTabColumnsTlDTO.setCbbTabColumnsId(columnId);
				cbbTabColumnsTlDTO.setColumnsShowName(columnsShowName);
				cbbTabColumnsTlDTO.setDescription(description);
				cbbTabColumnsTlService.insertCbbTabColumnsTl(cbbTabColumnsTlDTO);

			}

			// 添加通用代码（取系统初始化字段信息）
			// 复制通用代码信息（CBB_TEMPLET_SYS_CODE表）
			String codeSql = "SELECT T.SYS_LOOKUP_ID,T.REMARK FROM CBB_TEMPLET_SYS_CODE T WHERE T.FIELD_ID = '" + fieldId + "'";
			List<Object[]> codeList = this.hibernateDao.findBySQL(codeSql);
			if (codeList != null && codeList.size() > 0) {
				CbbTabColSysCode cbbTabColSysCode = new CbbTabColSysCode();
				cbbTabColSysCode.setSysLookupId(codeList.get(0)[0].toString());
				cbbTabColSysCode.setRemark(codeList.get(0)[1] == null ? "" : codeList.get(0)[1].toString());
				String id = ComUtil.getId();
				cbbTabColSysCode.setId(id);
				cbbTabColSysCode.setTableId(tableId);
				cbbTabColSysCode.setColumnId(columnId);
				cbbTabColSysCode.setOrgId(orgId);
				cbbTabColSysCode.setDeptId(deptId);
				cbbTabColSysCode.setSysId(sysId);
				PojoUtil.setSysProperties(cbbTabColSysCode, OpType.insert);
				hibernateDao.save(cbbTabColSysCode);
				SysLogUtil.log(cbbTabColSysCode, null, OpType.insert, OpResult.success);
			}
			// 复制通用代码信息（CBB_TEMPLET_CODE表）
			String codeSql2 = "SELECT T.CODE_ORDER,T.CODE_IS_VALID,T.LOOKUP_NAME,T.LOOKUP_CODE,T.REMARK,T.ID FROM CBB_TEMPLET_CODE T WHERE T.FIELD_ID = '" + fieldId + "'";
			List<Object[]> codeList2 = this.hibernateDao.findBySQL(codeSql2);
			for (int j = 0; j < codeList2.size(); j++) {
				CbbTabColCode cbbTabColCode = new CbbTabColCode();
				cbbTabColCode.setCodeOrder(new BigDecimal(codeList2.get(j)[0].toString()));
				cbbTabColCode.setCodeIsValid(codeList2.get(j)[1].toString());
				cbbTabColCode.setLookupName(codeList2.get(j)[2].toString());
				cbbTabColCode.setLookupCode(codeList2.get(j)[3].toString());
				cbbTabColCode.setRemark(codeList2.get(j)[4] == null ? "" : codeList2.get(j)[4].toString());
				String id = ComUtil.getId();
				cbbTabColCode.setId(id);
				cbbTabColCode.setTableId(tableId);
				cbbTabColCode.setColumnId(columnId);
				cbbTabColCode.setDeptId(deptId);
				cbbTabColCode.setOrgId(orgId);
				cbbTabColCode.setSysId(sysId);
				PojoUtil.setSysProperties(cbbTabColCode, OpType.insert);
				hibernateDao.save(cbbTabColCode);
				SysLogUtil.log(cbbTabColCode, null, OpType.insert, OpResult.success);

				/****************复制通用代码多语言信息（针对CBB_TAB_COL_CODE表的多语言信息）*************************/
				String codeSqlLanguange = "SELECT T.SYS_LANGUAGE_CODE,T.COLUMNS_SHOW_NAME,T.DESCRIPTION,T.ID FROM CBB_TEMPLET_CODE_TL T WHERE  T.CBB_TEMPLET_CODE_ID = '" + codeList2.get(j)[5].toString() + "'";
				List<Object[]> LanguangeCodeList2 = this.hibernateDao.findBySQL(codeSqlLanguange);
				for (int i2 = 0; i2 < LanguangeCodeList2.size(); i2++) {
					CbbTabColCodeTlDTO cbbTabColCodeTlDTO = new CbbTabColCodeTlDTO();
					cbbTabColCodeTlDTO.setCbbTabColCodeId(cbbTabColCode.getId());
					cbbTabColCodeTlDTO.setSysLanguageCode(LanguangeCodeList2.get(i2)[0].toString());
					cbbTabColCodeTlDTO.setColumnsShowName(LanguangeCodeList2.get(i2)[1].toString());
					cbbTabColCodeTlDTO.setDescription(LanguangeCodeList2.get(i2)[2] == null ? "" : LanguangeCodeList2.get(i2)[2].toString());
					cbbTabColCodeTlService.insertCbbTabColCodeTl(cbbTabColCodeTlDTO);
				}

			}
		}
		// 3.向CBB_TAB_NODE插入记录
		Map<String, Object> param2 = new HashMap<String, Object>();
		param2.put("TAB_FLAG", tabFlag);
		createCbbTabNodeByIntfs(orgId, deptId, sysId, nodeId, tableId, loginUserId, loginIp, param2);
		// 4.调用创建实体表存储过程
		insertdbTable(tableId, sysId, orgId);
		// 5.调用表单接口，新增表单相关信息
		billDefineManagerIntfsService.createCbbTabFormByIntfs(orgId, deptId, sysId, nodeId, nodeName, tableId);
	}

	/**
	 * 根据列ID，获取该列的组合项配置信息
	 *
	 * @author 朱锋
	 * @param tableId
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbColumnsConfigGropuByColIdByIntfs(String colId) throws Exception {
		List<Map<String, Object>> listColConfigGroup = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT * FROM CBB_TAB_COL_CONFIG_GROUP WHERE SOURCE_COLUMN_ID = '" + colId + "' ORDER BY GROUP_ORDER");
		listColConfigGroup = jdbcAvicit.queryForMap(sbSql.toString(), null);
		return listColConfigGroup;
	}

	/**
	 * 根据列ID，获取该列的组合项配置信息
	 *
	 * @author 钟一华
	 * @param colId
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbColumnsConfigGropuAndSourceColNameByColIdByIntfs(String colId) throws Exception {
		List<Map<String, Object>> listColConfigGroup = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT COL.COL_NAME, CG.*\n");
		sbSql.append("  FROM CBB_TAB_COL_CONFIG_GROUP CG\n");
		sbSql.append("  LEFT JOIN CBB_TAB_COLUMNS COL\n");
		sbSql.append("    ON COL.ID = CG.SOURCE_COLUMN_ID\n");
		sbSql.append(" WHERE CG.SOURCE_COLUMN_ID = '" + colId + "'");
		listColConfigGroup = jdbcAvicit.queryForMap(sbSql.toString(), null);
		return listColConfigGroup;
	}

	/**
	 * 根据表ID获取分类检索字段字段信息
	 *
	 * @author 郭亮
	 * @param tableId
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<Map<String, Object>> getColSearchByTableId(String tableId) throws Exception {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		if (null == tableId || "".equals(tableId) || "null".equals(tableId)) {
			throw new Exception("调用方法时tableId参数不存在，请检查！");
		}
		String sql = "SELECT CTCS.*,CTC.COL_NAME,CTC.COL_TYPE FROM CBB_TAB_COL_SEARCH CTCS LEFT JOIN CBB_TAB_COLUMNS CTC ON CTC.ID = CTCS.COLUMN_ID WHERE CTC.TABLE_ID = '" + tableId + "' ORDER BY CTCS.SEARCH_ORDER";
		list = jdbcAvicit.queryForMap(sql, null);
		return list;
	}

	/**
	 * 获取数据排序字段
	 *
	 * @author 朱锋
	 * @param tableId
	 * @param sysId
	 * @param orgId
	 * @param deptId
	 * @return List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getColDataOrderByTableId(String tableId, String sysId, String orgId, String deptId) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CTCS.COLUMN_ID, CTC.COL_NAME, CTC.COL_LABEL, CTCS.SORT_CODE, CTCS.SORT_ORDER\n");
		sbSql.append("  FROM CBB_TAB_COL_SORT CTCS\n");
		sbSql.append("  LEFT JOIN CBB_TAB_COLUMNS CTC\n");
		sbSql.append("    ON CTC.ID = CTCS.COLUMN_ID\n");
		sbSql.append(" WHERE CTCS.ORG_ID = '" + orgId + "'\n");
		// sbSql.append("   AND CTCS.DEPT_ID = '" + deptId + "'\n");
		sbSql.append("   AND CTCS.SYS_ID = '" + sysId + "'\n");
		sbSql.append("   AND CTC.COL_IS_DISPLAY = 'Y'\n");
		sbSql.append("   AND CTCS.TABLE_ID = '" + tableId + "'\n");
		// sbSql.append(" ORDER BY CTCS.SORT_CODE");
		sbSql.append(" ORDER BY CTCS.SORT_ORDER");
		list = jdbcAvicit.queryForMap(sbSql.toString(), null);
		return list;
	}

	/**
	 * 获取排序主表信息（分页）
	 *
	 * @param pageNo
	 * @param pageSize
	 * @param parameter
	 * @return
	 * @throws Exception
	 */
	@Override
	public Page<Map<String, Object>> getPageTabSortList(int pageNo, int pageSize, Map<String, Object> parameter) throws Exception {
		String tableId = (String) parameter.get("tableId");
		String isTemplet = (String) parameter.get("isTemplet");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("WITH T1 AS\n");
		sbSql.append(" (SELECT CT.ID            AS TABLE_ID,\n");
		sbSql.append("         CTC.ID           AS COL_ID,\n");
		sbSql.append("         CTC.COL_ORDER,\n");
		sbSql.append("         CTC.COL_NAME,\n");
		sbSql.append("         CTC.COL_LABEL,\n");
		sbSql.append("         CTCS.SORT_CODE,\n");
		sbSql.append("         CTCS.SORT_ORDER,\n");
		sbSql.append("         CTC.COL_IS_DISPLAY,\n");
		sbSql.append("         CTC.COL_IS_SYS\n");
		sbSql.append("    FROM CBB_TABLES CT\n");
		sbSql.append("    LEFT JOIN CBB_TAB_COLUMNS CTC\n");
		sbSql.append("      ON CTC.TABLE_ID = CT.ID\n");
		sbSql.append("    LEFT JOIN CBB_TAB_COL_SORT CTCS\n");
		sbSql.append("      ON CTCS.COLUMN_ID = CTC.ID\n");
		sbSql.append("   WHERE CT.ID = '" + tableId + "'\n");
		sbSql.append("     AND (CTC.COL_IS_SYS = 'N' OR CTC.COL_IS_DISPLAY = 'Y')\n");
		sbSql.append("   ORDER BY CTC.COL_ORDER,CTC.COL_NAME),\n");
		sbSql.append("T2 AS\n");
		sbSql.append(" (SELECT CT.ID            AS TABLE_ID,\n");
		sbSql.append("         CTC.ID           AS COL_ID,\n");
		sbSql.append("         CTC.COL_ORDER,\n");
		sbSql.append("         CTC.COL_NAME,\n");
		sbSql.append("         CTC.COL_LABEL,\n");
		sbSql.append("         CTCS.SORT_CODE,\n");
		sbSql.append("         CTCS.SORT_ORDER,\n");
		sbSql.append("         CTC.COL_IS_DISPLAY,\n");
		sbSql.append("         CTC.COL_IS_SYS\n");
		sbSql.append("    FROM CBB_TABLES CT\n");
		sbSql.append("    LEFT JOIN CBB_TAB_COLUMNS CTC\n");
		sbSql.append("      ON CTC.TABLE_ID = CT.ID\n");
		sbSql.append("    LEFT JOIN CBB_TAB_COL_SORT CTCS\n");
		sbSql.append("      ON CTCS.COLUMN_ID = CTC.ID\n");
		sbSql.append("   WHERE CT.ID = '" + tableId + "'\n");
		sbSql.append("     AND CTC.COL_IS_SYS = 'Y'\n");
		sbSql.append("     AND CTC.COL_IS_DISPLAY = 'N'\n");
		sbSql.append("   ORDER BY CTC.COL_ORDER,CTC.COL_NAME),\n");
		sbSql.append("T3 AS\n");
		sbSql.append(" (SELECT T1.*\n");
		sbSql.append("    FROM T1\n");
		sbSql.append("  UNION ALL\n");
		sbSql.append("  SELECT T2.* FROM T2)\n");
		sbSql.append("SELECT T3.*\n");
		sbSql.append("  FROM T3\n");
		if ("N".equals(isTemplet)) {
			sbSql.append(" WHERE T3.COL_IS_DISPLAY = 'Y'");
		}
		Page<Map<String, Object>> pageBean = new Page<Map<String, Object>>(pageNo, pageSize);
		jdbcAvicit.getDatesByPageForMap(pageBean, sbSql.toString(), parameter, null);
		return pageBean;
	}

	/**
	 * 获取表单排列数据
	 * @param parameter
	 * @return
	 * @throws Exception Map<String,Object>
	 * @throws
	 */
	@Override
	public Map<String, Object> getColumnPageMap(Map<String, Object> parameter) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();// 返回值集合
		String sysId = (String) parameter.get("sysId");// 系统ID
		String orgId = (String) parameter.get("orgId");// 组织ID
		String deptId = (String) parameter.get("deptId");// 部门ID
		String tableId = (String) parameter.get("tableId");// 表ID
		String nodeId = (String) parameter.get("nodeId");// 数据节点Id
		String flag = (String) parameter.get("flag");// (1-是否添加或编辑显示 2-是否列表显示 3-是否详细显示 4-是否查询显示 0-全部字段显示)
		String formId = "";// 表单ID
		int column = 3;// 默认列数,默认3
		String tabNodeId = "";
		// 调用rest服务，获取模板文件夹NODE_ID
		if (null != nodeId && !"".equals(nodeId) && !"null".equals(nodeId)) {
			// 调用rest服务，查找该数据节点的模板文件夹NODE_ID
			String modelNodeId = billDefineManagerIntfsService.getCbbTabModelNodeIdByNodeId(nodeId);
			if (null != modelNodeId && !"".equals(modelNodeId) && !"null".equals(modelNodeId)) {
				tabNodeId = getCbbTabNodeIdByIntfs(orgId, deptId, sysId, modelNodeId, tableId);
			}
		}
		// 查找该表FormId及默认列数值
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CTFN.FORM_ID,CTFN.ATTRIBUTE_11\n");
		sbSql.append("  FROM CBB_TAB_FORM_NODE CTFN\n");
		sbSql.append(" WHERE CTFN.TAB_NODE_ID = '" + tabNodeId + "'\n");
		List<Object[]> objList = hibernateDao.findBySQL(sbSql.toString());
		if (objList.size() > 0) {
			Object[] ob = objList.get(0);
			formId = String.valueOf(ob[0]);
			String coln = String.valueOf(ob[1]);
			if (coln != null && !"".equals(coln) && !"null".equals(coln)) {
				column = Integer.parseInt(coln);
			}
		}
		if (null != nodeId && !"".equals(nodeId) && !"null".equals(nodeId)) {
			// 调用rest服务，查找节点著录定义配置信息
			tabNodeId = billDefineManagerIntfsService.getCbbTabNodeIdByTableId(sysId, tableId, nodeId);
		}
		// 判断改节点下是否已经配置了节点著录定义
		StringBuffer sbSql2 = new StringBuffer();
		sbSql2.append("SELECT COUNT(*)\n");
		sbSql2.append("  FROM CBB_TAB_NODE_RECORD CTNR\n");
		sbSql2.append(" WHERE CTNR.TAB_NODE_ID = '" + tabNodeId + "'");
		List<Object> objListco2 = hibernateDao.findBySQL(sbSql2.toString());
		boolean isConfig = false;// 默认为没有配置
		if (Integer.parseInt(String.valueOf(objListco2.get(0))) > 0) {
			isConfig = true;
		}
		// 根据formId查找配置的列信息
		List<Integer> colSpan = new ArrayList<Integer>();// 横向栏数
		List<Integer> rowSpan = new ArrayList<Integer>();// 纵向栏数
		StringBuffer sbSql1 = new StringBuffer();
		if (isConfig) {
			// 如果该节点配置了节点著录定义
			sbSql1.append("SELECT CTFC.FORM_VERTICAL, CTFC.FORM_HORIZONTAL\n");
			sbSql1.append("  FROM CBB_TAB_NODE_RECORD CTNR\n");
			sbSql1.append("  LEFT JOIN CBB_TAB_COLUMNS CTC\n");
			sbSql1.append("    ON CTC.ID = CTNR.COLUMN_ID\n");
			sbSql1.append("  LEFT JOIN CBB_TAB_FORM_CONFIG CTFC\n");
			sbSql1.append("    ON CTFC.COLUMN_ID = CTC.ID\n");
			sbSql1.append(" WHERE CTNR.TAB_NODE_ID = '" + tabNodeId + "'\n");
			if ("1".equals(flag)) {
				sbSql1.append("   AND CTNR.COL_IS_VISIBLE = 'Y'\n");
			} else if ("2".equals(flag)) {
				sbSql1.append("   AND CTNR.COL_IS_TAB_VISIBLE = 'Y'\n");
			} else if ("3".equals(flag)) {
				sbSql1.append("   AND CTNR.COL_IS_DETAIL = 'Y'\n");
			} else if ("4".equals(flag)) {
				sbSql1.append("   AND CTNR.COL_IS_SEARCH = 'Y'\n");
			}
			sbSql1.append(" ORDER BY CTFC.ATTRIBUTE_11,CTC.COL_NAME");
		} else {
			// 如果没有配置
			sbSql1.append("SELECT CTFC.FORM_VERTICAL, CTFC.FORM_HORIZONTAL\n");
			sbSql1.append("  FROM CBB_TAB_FORM_CONFIG CTFC\n");
			sbSql1.append("  LEFT JOIN CBB_TAB_COLUMNS CTC\n");
			sbSql1.append("    ON CTC.ID = CTFC.COLUMN_ID\n");
			sbSql1.append(" WHERE CTFC.FORM_ID = '" + formId + "'\n");
			if ("1".equals(flag)) {
				sbSql1.append("   AND CTC.COL_IS_DISPLAY = 'Y'\n");
				sbSql1.append("   AND CTC.COL_IS_VISIBLE = 'Y'\n");
			} else if ("2".equals(flag)) {
				sbSql1.append("   AND CTC.COL_IS_DISPLAY = 'Y'\n");
				sbSql1.append("   AND CTC.COL_IS_TAB_VISIBLE = 'Y'\n");
			} else if ("3".equals(flag)) {
				sbSql1.append("   AND CTC.COL_IS_DISPLAY = 'Y'\n");
				sbSql1.append("   AND CTC.COL_IS_DETAIL = 'Y'\n");
			} else if ("4".equals(flag)) {
				sbSql1.append("   AND CTC.COL_IS_DISPLAY = 'Y'\n");
				sbSql1.append("   AND CTC.COL_IS_SEARCH = 'Y'\n");
			}
			sbSql1.append(" ORDER BY CTFC.ATTRIBUTE_11,CTC.COL_NAME");
		}
		List<Object[]> objListcol = hibernateDao.findBySQL(sbSql1.toString());
		for (int i = 0; i < objListcol.size(); i++) {
			Object[] ob = objListcol.get(i);
			int formHorizontal = Integer.parseInt(String.valueOf(ob[1]));// 横向栏数
			int formVertical = Integer.parseInt(String.valueOf(ob[0]));// 纵向栏数
			colSpan.add(formHorizontal);
			rowSpan.add(formVertical);
		}
		map.put("MODEL_COLUMN", column);
		map.put("COL_SPAN", colSpan);
		map.put("ROW_SPAN", rowSpan);
		return map;
	}

	@Override
	public Map<String, Object> getColumnPageMapItera(Map<String, Object> parameter, List<Map<String, Object>> columnInfoMap) throws Exception {
		Map<String, Object> map = new HashMap();
		String sysId = (String)parameter.get("sysId");
		String orgId = (String)parameter.get("orgId");
		String deptId = (String)parameter.get("deptId");
		String tableId = (String)parameter.get("tableId");
		String nodeId = (String)parameter.get("nodeId");
		String flag = (String)parameter.get("flag");
		String archiveStatus = (String) parameter.get("archiveStatus");//数据状态 //1 预归档 2著录 3馆藏
		String formId = "";
		int column = 3;
		String tabNodeId = "";
		if ((null != nodeId) && (!"".equals(nodeId)) && (!"null".equals(nodeId)))
		{
			String modelNodeId = this.billDefineManagerIntfsService.getCbbTabModelNodeIdByNodeId(nodeId);
			if ((null != modelNodeId) && (!"".equals(modelNodeId)) && (!"null".equals(modelNodeId))) {
				tabNodeId = getCbbTabNodeIdByIntfs(orgId, deptId, sysId, modelNodeId, tableId);
			}
		}
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CTFN.FORM_ID,CTFN.ATTRIBUTE_11\n");
		sbSql.append("  FROM CBB_TAB_FORM_NODE CTFN\n");
		sbSql.append(" WHERE CTFN.ARCHIVE_STATUS = '"+archiveStatus+"'\n");
		sbSql.append(" AND CTFN.TAB_NODE_ID = '" + tabNodeId + "'\n");
		List<Object[]> objList = this.hibernateDao.findBySQL(sbSql.toString());
		if (objList.size() > 0)
		{
			Object[] ob = objList.get(0);
			formId = String.valueOf(ob[0]);
			String coln = String.valueOf(ob[1]);
			if ((coln != null) && (!"".equals(coln)) && (!"null".equals(coln))) {
				column = Integer.parseInt(coln);
			}
		}
		if ((null != nodeId) && (!"".equals(nodeId)) && (!"null".equals(nodeId))) {
			tabNodeId = this.billDefineManagerIntfsService.getCbbTabNodeIdByTableId(sysId, tableId, nodeId);
		}
		StringBuffer sbSql2 = new StringBuffer();
		sbSql2.append("SELECT COUNT(*)\n");
		sbSql2.append("  FROM CBB_TAB_NODE_RECORD CTNR\n");
		sbSql2.append(" WHERE CTNR.TAB_NODE_ID = '" + tabNodeId + "'");
		List<Object> objListco2 = this.hibernateDao.findBySQL(sbSql2.toString());
		boolean isConfig = false;
		if (Integer.parseInt(String.valueOf(objListco2.get(0))) > 0) {
			isConfig = true;
		}
		List<Integer> colSpan = new ArrayList();
		List<Integer> rowSpan = new ArrayList();
		StringBuffer sbSql1 = new StringBuffer();
		if (isConfig)
		{
			sbSql1.append("SELECT CTFC.FORM_VERTICAL, CTFC.FORM_HORIZONTAL\n");
			sbSql1.append("  FROM CBB_TAB_NODE_RECORD CTNR\n");
			sbSql1.append("  LEFT JOIN CBB_TAB_COLUMNS CTC\n");
			sbSql1.append("    ON CTC.ID = CTNR.COLUMN_ID\n");
			sbSql1.append("  LEFT JOIN CBB_TAB_FORM_CONFIG CTFC\n");
			sbSql1.append("    ON CTFC.COLUMN_ID = CTC.ID\n");
			sbSql1.append(" WHERE 1=1\n");
			if ("1".equals(flag)) {
				sbSql1.append("   AND CTNR.COL_IS_VISIBLE = 'Y'\n");
			} else if ("2".equals(flag)) {
				sbSql1.append("   AND CTNR.COL_IS_TAB_VISIBLE = 'Y'\n");
			} else if ("3".equals(flag)) {
				sbSql1.append("   AND CTNR.COL_IS_DETAIL = 'Y'\n");
			} else if ("4".equals(flag)) {
				sbSql1.append("   AND CTNR.COL_IS_SEARCH = 'Y'\n");
			}

			//SanXiaFiels update by huangjian  start
			String columnIds = "";
			for (Map<String, Object> col:columnInfoMap) {
				columnIds += ",'"+col.get("ID")+"'";
			}
			if(!StringUtils.isEmpty(columnIds)){
				columnIds = columnIds.replaceFirst(",","");
			}
			sbSql1.append(" AND CTC.ID IN ("+columnIds+")");
			//SanXiaFiels update by huangjian end
			sbSql1.append(" AND CTNR.TAB_NODE_ID = '" + tabNodeId + "'\n");
			sbSql1.append(" ORDER BY CTFC.ATTRIBUTE_11,CTC.COL_NAME");
		}
		else
		{
			sbSql1.append("SELECT CTFC.FORM_VERTICAL, CTFC.FORM_HORIZONTAL\n");
			sbSql1.append("  FROM CBB_TAB_FORM_CONFIG CTFC\n");
			sbSql1.append("  LEFT JOIN CBB_TAB_COLUMNS CTC\n");
			sbSql1.append("    ON CTC.ID = CTFC.COLUMN_ID\n");
			sbSql1.append(" WHERE 1=1\n");
			if ("1".equals(flag))
			{
				sbSql1.append("   AND CTC.COL_IS_DISPLAY = 'Y'\n");
				sbSql1.append("   AND CTC.COL_IS_VISIBLE = 'Y'\n");

				//sbSql1.append("   AND CTFC.COL_IS_DETAIL = 'Y'\n");
			}
			else if ("2".equals(flag))
			{
				sbSql1.append("   AND CTC.COL_IS_DISPLAY = 'Y'\n");
				sbSql1.append("   AND CTC.COL_IS_TAB_VISIBLE = 'Y'\n");
			}
			else if ("3".equals(flag))
			{
				sbSql1.append("   AND CTC.COL_IS_DISPLAY = 'Y'\n");
				sbSql1.append("   AND CTC.COL_IS_DETAIL = 'Y'\n");
			}
			else if ("4".equals(flag))
			{
				sbSql1.append("   AND CTC.COL_IS_DISPLAY = 'Y'\n");
				sbSql1.append("   AND CTC.COL_IS_SEARCH = 'Y'\n");
			}
			//SanXiaFiels update by huangjian  start
			String columnIds = "";
			for (Map<String, Object> col:columnInfoMap) {
				columnIds += ",'"+col.get("ID")+"'";
			}
			if(!StringUtils.isEmpty(columnIds)){
				columnIds = columnIds.replaceFirst(",","");
				//SanXiaFiles update by huangjian 防止columnInfoMap 为空 2019-08-09
				sbSql1.append(" AND CTC.ID IN ("+columnIds+")");
			}
			sbSql1.append(" AND CTFC.FORM_ID = '" + formId + "'\n");
			//SanXiaFiels update by huangjian end
			sbSql1.append(" ORDER BY CTFC.ATTRIBUTE_11,CTC.COL_NAME");
		}
		List<Object[]> objListcol = this.hibernateDao.findBySQL(sbSql1.toString());
		for (int i = 0; i < objListcol.size(); i++)
		{
			Object[] ob = objListcol.get(i);
			int formHorizontal = Integer.parseInt(String.valueOf(ob[1]));
			int formVertical = Integer.parseInt(String.valueOf(ob[0]));
			colSpan.add(Integer.valueOf(formHorizontal));
			rowSpan.add(Integer.valueOf(formVertical));
		}
		map.put("MODEL_COLUMN", Integer.valueOf(column));
		map.put("COL_SPAN", colSpan);
		map.put("ROW_SPAN", rowSpan);
		return map;
	}

	/**
	 * 获取公共字段表中的字段信息
	 * @author 郭亮
	 * @param param key1:sysId value:String 必填
	 * 				key2:orgId value:String 必填
	 * 				key3:tabName
	 * 				key4:tabId
	 * 				key5:type value:String(1：查询字段；2：列表显示字段) 必填
	 * 				key6:isAll value:String(Y：所有字段；N：可见字段) 必填
	 * @return
	 * @throws Exception List<Map<String,Object>>
	 */
	@Override
	public List<Map<String, Object>> getPublicField(Map<String, Object> param) throws Exception {
		List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
		if (null == param || param.size() == 0) {
			throw new Exception("调用方法时，param参数不存在，请检查！");
		}
		if (!param.containsKey("sysId")) {
			throw new Exception("调用方法时，sysId参数不存在，请检查！");
		}
		if (!param.containsKey("orgId")) {
			throw new Exception("调用方法时，orgId参数不存在，请检查！");
		}
		if (!param.containsKey("type")) {
			throw new Exception("调用方法时，type参数不存在，请检查！");
		}
		if (!param.containsKey("isAll")) {
			throw new Exception("调用方法时，isAll参数不存在，请检查！");
		}
		String sysId = (String) param.get("sysId");
		String orgId = (String) param.get("orgId");
		String tabName = (String) param.get("tabName");
		String tabId = (String) param.get("tabId");
		String type = (String) param.get("type");
		String isAll = (String) param.get("isAll");
		if (null == sysId || "".equals(sysId) || "null".equals(sysId)) {
			throw new Exception("调用方法时，sysId参数不存在，请检查！");
		}
		if (null == orgId || "".equals(orgId) || "null".equals(orgId)) {
			throw new Exception("调用方法时，orgId参数不存在，请检查！");
		}
		if (null == type || "".equals(type) || "null".equals(type)) {
			throw new Exception("调用方法时，type参数不存在，请检查！");
		}
		if (null == isAll || "".equals(isAll) || "null".equals(isAll)) {
			throw new Exception("调用方法时，isAll参数不存在，请检查！");
		}
		// 当tableId为空时，根据tableName获取tableId
		if (null == tabId || "".equals(tabId) || "null".equals(tabId)) {
			if (null == tabName || "".equals(tabName) || "null".equals(tabName)) {
				throw new Exception("调用方法时，tabId、tabName都不存在，请检查！");
			}
			tabId = getCbbTableIdByIntfs(orgId, "", sysId, tabName);// 获取TABLEID
		}
		// 根据tableId获取列信息
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.ID,\n");
		sbSql.append("       T.TABLE_ID,\n");
		sbSql.append("       T.COL_NAME,\n");
		sbSql.append("       T.COL_LABEL,\n");
		sbSql.append("       T.COL_TYPE,\n");
		sbSql.append("       T.COL_LENGTH,\n");
		sbSql.append("       T.COL_DECIMAL,\n");
		sbSql.append("       T.COL_IS_MUST,\n");
		sbSql.append("       T.COL_DROPDOWN_TYPE,\n");
		sbSql.append("       T.COL_RULE_NAME,\n");
		sbSql.append("       T.COL_RULE_TITLE,\n");
		sbSql.append("       T.CUSTOM_PATH,\n");
		sbSql.append("       T.COL_SHOW_FORMAT\n");
		sbSql.append(" FROM CBB_TAB_COLUMNS T WHERE 1=1\n");
		// sbSql.append(" AND T.ORG_ID = '" + orgId + "'\n");
		sbSql.append(" AND T.SYS_ID = '" + sysId + "'\n");
		sbSql.append(" AND T.TABLE_ID = '" + tabId + "'\n");
		if ("N".equals(isAll)) { // 可见字段
			sbSql.append(" AND T.COL_IS_DISPLAY = 'Y'\n");
		}
		if ("1".equals(type)) { // 查询区域字段
			sbSql.append(" AND T.COL_IS_SEARCH = 'Y'\n");
		} else if ("2".equals(type)) { // 列表显示字段
			sbSql.append(" AND T.COL_IS_TAB_VISIBLE = 'Y'\n");
		}
		sbSql.append(" ORDER BY T.COL_ORDER,T.COL_NAME");
		listMap = this.jdbcAvicit.queryForMap(sbSql.toString(), null);
		// 循环判断字段是否为特殊字段
		for (Map<String, Object> map : listMap) {
			String colDropdownType = (String) map.get("COL_DROPDOWN_TYPE");
			if ("3".equals(colDropdownType)) {
				map.put("IS_COMM_FIELD", "Y");
			} else {
				map.put("IS_COMM_FIELD", "N");
			}
		}
		return listMap;
	}

	/**
	 * 获取唯一索引
	 * @author 路丹娜
	 * @param param key1:sysId value:String
	 * 				key2:orgId value:String
	 * 				key3:deptId value:String
	 * 				key4:tableId 必填
	 * 				key5:mapObj value:Map<String, Object>（表单信息，用来获取value） 必填
	 * 				key6:flag value:String(flag为"only"时，只需获取是否有唯一索引，不需获取具体的字段信息)
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getTableIndexByParam(Map<String, Object> param) throws Exception {
		List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
		Map<String, Object> paramMap = new HashMap<String, Object>();
		String tableId = (String) param.get("tableId");
		String dataId = (String) param.get("dataId");
		String flag = (String) param.get("flag");
		Map<String, Object> mapObj = (Map<String, Object>) param.get("mapObj");
		// 根据tableId获取tableName
		CbbTables cbbTables = getCbbTablesById(tableId);
		String tableName = cbbTables.getTableName();
		// 根据tableId获取唯一索引
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT CTCI.INDEX_TYPE,CTCI.INDEX_NAME,CTCI.COLUMN_ID,CTCI.TABLE_ID\n");
		sbSql.append(" FROM CBB_TAB_COL_INDEX CTCI\n");
		sbSql.append(" WHERE CTCI.TABLE_ID = '" + tableId + "'");
		sbSql.append(" AND CTCI.INDEX_TYPE = '2'");
		List<Map<String, Object>> list = this.jdbcAvicit.queryForMap(sbSql.toString(), null);
		boolean isExist = false;// 值是否已存在
		String colName = "";// 字段名
		String value = "";// 字段value
		String columnId = "";
		String colLabel = "";// 字段中文名
		paramMap.put("isHave", "1");// 1,不存在唯一索引 2,存在唯一索引
		if (list.size() > 0) {
			paramMap.put("isHave", "2");
			if (!"only".equals(flag)) {
				for (Map<String, Object> map : list) {
					String columnIds = (String) map.get("COLUMN_ID");
					String[] arr = columnIds.split(",");
					if (arr.length > 1) {
						StringBuffer sqlCount = new StringBuffer("");
						sqlCount.append("SELECT COUNT(*) FROM " + tableName + " WHERE 1=1 ");
						StringBuffer colLabels = new StringBuffer("");
						for (int i = 0; i < arr.length; i++) {
							columnId = arr[i];
							StringBuffer sqlColumnName = new StringBuffer();
							sqlColumnName.append("SELECT T.COL_NAME,T.COL_LABEL FROM CBB_TAB_COLUMNS T\n");
							sqlColumnName.append("WHERE T.ID = '" + columnId + "'");
							List<Map<String, Object>> columnName = this.jdbcAvicit.queryForMap(sqlColumnName.toString(), null);
							for (Map<String, Object> m : columnName) {
								colName = (String) m.get("COL_NAME");
								colLabel = (String) m.get("COL_LABEL");
							}
							// 获取该字段的value
							value = (String) mapObj.get(colName);
							sqlCount.append(" AND " + colName + " = '" + value + "' ");
							colLabels.append(colLabel);
							if (i < arr.length - 1) {
								colLabels.append(",");
							}
						}
						// 查询
						List<Object> sqlCountList = this.hibernateDao.findBySQL(sqlCount.toString());
						paramMap.put("message", colLabels.toString());
						if (sqlCountList.size() > 0) {
							if (Integer.parseInt(String.valueOf(sqlCountList.get(0))) > 0) {// 该值已存在
								isExist = true;
							}
						}
					} else {
						StringBuffer sqlCount = new StringBuffer("");
						StringBuffer colLabels = new StringBuffer("");
						sqlCount.append("SELECT COUNT(*) FROM " + tableName + " WHERE 1=1 ");
						StringBuffer sqlColumnName = new StringBuffer();
						sqlColumnName.append("SELECT T.COL_NAME,T.COL_LABEL FROM CBB_TAB_COLUMNS T\n");
						sqlColumnName.append("WHERE T.ID = '" + columnIds + "'");
						List<Map<String, Object>> columnName = this.jdbcAvicit.queryForMap(sqlColumnName.toString(), null);
						for (Map<String, Object> m : columnName) {
							colName = (String) m.get("COL_NAME");
							colLabel = (String) m.get("COL_LABEL");
						}
						// 获取该字段的value
						value = (String) mapObj.get(colName);
						// 查询
						sqlCount.append(" AND " + colName + " = '" + value + "'");
						if (null != dataId && !"".equals(dataId)) {
							sqlCount.append(" AND ID <> '" + dataId + "'");

						}
						List<Object> sqlCountList = this.hibernateDao.findBySQL(sqlCount.toString());
						colLabels.append(colLabel);
						paramMap.put("message", colLabels.toString());
						if (sqlCountList.size() > 0) {
							if (Integer.parseInt(String.valueOf(sqlCountList.get(0))) > 0) {// 该值已存在
								isExist = true;
							}
						}
					}
					if (isExist == true) {
						paramMap.put("isExist", isExist);
						break;
					}
				}
			}
		}
		paramMap.put("isExist", isExist);
		listMap.add(paramMap);
		return listMap;
	}

	/**
	 * 根据列id和语言code获取 列名
	 * @param columnId
	 * @param languageCode
	 * @return
	 * @throws Exception String
	 * @throws
	 */
	@Override
	public String getColumnLabelByColumnIdAndLanguageCode(String columnId, String languageCode) throws Exception {
		CbbTabColumnsTlDTO colDto = cbbTabColumnsTlService.getSysLookupTypeTlByLanguageCode(columnId, languageCode);
		if (null != colDto) {
			return colDto.getColumnsShowName();
		}
		return "";
	}

	/**
	 * 根据tableId 和 生成方式获取列信息
	 * @param param
	 * @return
	 * @throws Exception List<CbbTabColumns>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getColumnsByParam(Map<String, Object> param) throws Exception {
		String sql = "select * from cbb_tab_columns t where t.table_id = '" + param.get("TABLE_ID") + "' and t.col_gene_method = '" + param.get("COL_GENE_METHOD") + "'"
				+ " and t.col_gene_method_rule <> 'currentUser' and t.col_gene_method_rule <> 'currentDeptId' and t.col_gene_method_rule <> 'currentDeptName' and t.col_gene_method_rule <> 'currentOrg'"
				+ " and t.col_gene_method_rule <> 'parentDeptId' and t.col_gene_method_rule <> 'parentDeptCode' and t.col_gene_method_rule <> 'parentDeptName' and t.col_gene_method_rule <> 'parentDept'" + " and t.col_gene_method_rule <> 'currentUserName'";
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sql);
		return list;
	}

	/**
	 * 根据tableId 和 生成方式获取列信息
	 * @param param
	 * @return
	 * @throws Exception List<CbbTabColumns>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getColumnsByParameter(Map<String, Object> param) throws Exception {
		String sql = "select * from cbb_tab_columns t left join cbb_tables tt on tt.id = t.table_id where tt.table_name = '" + param.get("TABLE_NAME") + "' and t.col_gene_method = '" + param.get("COL_GENE_METHOD") + "'";
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sql);
		return list;
	}

	/**
	 * 根据列id获取当前列的通用代码值
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param param
	 * @return
	 * @throws Exception Map<String,Object>
	 * @throws
	 */
	@Override
	public Map<String, Object> getColumnLookupByColumnId(String orgId, String deptId, String sysId, Map<String, Object> param) throws Exception {
		String columnId = "";
		if (!param.containsKey("COLUMN_ID") || null == param.get("COLUMN_ID")) {
			throw new Exception("调用方法时COLUMN_ID参数不存在，请检查！");
		}
		columnId = (String) param.get("COLUMN_ID");
		Map<String, Object> resultMap = new HashMap<String, Object>();
		// 判断该字段是否存在通用代码
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("WITH T1 AS\n");
		sbSql.append(" (SELECT CTCC.LOOKUP_NAME, CTCC.LOOKUP_CODE, CTCC.CODE_ORDER\n");
		sbSql.append("    FROM CBB_TAB_COL_CODE CTCC\n");
		sbSql.append("   WHERE CTCC.COLUMN_ID = '" + columnId + "' AND CTCC.CODE_IS_VALID = 'Y'\n");
		sbSql.append("  UNION\n");
		sbSql.append("  SELECT CLV.LOOKUP_NAME, CLV.LOOKUP_CODE, CLV.CODE_ORDER\n");
		sbSql.append("    FROM CBB_TAB_COL_SYS_CODE CTCSC\n");
		sbSql.append("    LEFT JOIN CBB_LOOKUP_V CLV\n");
		sbSql.append("      ON CLV.ID = CTCSC.SYS_LOOKUP_ID\n");
		sbSql.append("   WHERE CTCSC.COLUMN_ID = '" + columnId + "')\n");
		sbSql.append("SELECT T1.LOOKUP_NAME, T1.LOOKUP_CODE FROM T1 ORDER BY T1.CODE_ORDER");
		List<Object[]> colCodeList = hibernateDao.findBySQL(sbSql.toString());
		for (int j = 0; j < colCodeList.size(); j++) {
			Object obj[] = colCodeList.get(j);
			String lookupName = String.valueOf(obj[0]);// 显示值
			String lookupCode = String.valueOf(obj[1]);// 真实值
			resultMap.put(lookupCode, lookupName);
		}
		return resultMap;
	}

	/**
	 * 查询当前组织下公共字段中所有字段的通用代码值
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param param
	 * @return
	 * @throws Exception Map<String,Map<String,String>>
	 * @throws
	 */
	@Override
	public Map<String, Map<String, String>> getColumnLookupByPublicTable(String orgId, String deptId, String sysId, Map<String, Object> param) throws Exception {
		Map<String, Map<String, String>> mapCode = new HashMap<String, Map<String, String>>();// 返回值
		// 获取公共字段信息
		StringBuffer sbSqlpub = new StringBuffer();
		sbSqlpub.append("SELECT CTC.*\n");
		sbSqlpub.append("  FROM CBB_TAB_COLUMNS CTC\n");
		sbSqlpub.append("  LEFT JOIN CBB_TABLES CT\n");
		sbSqlpub.append("    ON CT.ID = CTC.TABLE_ID\n");
		sbSqlpub.append(" WHERE CT.SYS_ID = '" + sysId + "'");
		sbSqlpub.append("   AND (CTC.COL_DROPDOWN_TYPE = '1' OR CTC.COL_DROPDOWN_TYPE = '2')");
		sbSqlpub.append("   AND CT.TABLE_NAME = 'LANTOP_PUB_FIELD'\n");
		List<Map<String, Object>> listpub = jdbcAvicit.queryForMap(sbSqlpub.toString(), null);
		for (int i = 0; i < listpub.size(); i++) {
			Map<String, Object> mappub = listpub.get(i);
			String colId = String.valueOf(mappub.get("ID"));// 列ID
			String colName = String.valueOf(mappub.get("COL_NAME"));// 列英文名
			// 判断该字段是否存在通用代码
			StringBuffer sbSql = new StringBuffer();
			sbSql.append("WITH T1 AS\n");
			sbSql.append(" (SELECT CTCC.LOOKUP_NAME, CTCC.LOOKUP_CODE, CTCC.CODE_ORDER\n");
			sbSql.append("    FROM CBB_TAB_COL_CODE CTCC\n");
			sbSql.append("   WHERE CTCC.COLUMN_ID = '" + colId + "' AND CTCC.CODE_IS_VALID = 'Y'\n");
			sbSql.append("  UNION\n");
			sbSql.append("  SELECT CLV.LOOKUP_NAME, CLV.LOOKUP_CODE, CLV.CODE_ORDER\n");
			sbSql.append("    FROM CBB_TAB_COL_SYS_CODE CTCSC\n");
			sbSql.append("    LEFT JOIN CBB_LOOKUP_V CLV\n");
			sbSql.append("      ON CLV.ID = CTCSC.SYS_LOOKUP_ID\n");
			sbSql.append("   WHERE CTCSC.COLUMN_ID = '" + colId + "')\n");
			sbSql.append("SELECT T1.LOOKUP_NAME, T1.LOOKUP_CODE FROM T1 ORDER BY T1.CODE_ORDER");
			List<Object[]> colCodeList = hibernateDao.findBySQL(sbSql.toString());
			Map<String, String> map = new LinkedHashMap<String, String>();
			for (int j = 0; j < colCodeList.size(); j++) {
				Object obj[] = colCodeList.get(j);
				String lookupName = String.valueOf(obj[0]);// 显示值
				String lookupCode = String.valueOf(obj[1]);// 真实值
				map.put(lookupCode, lookupName);
			}
			mapCode.put(colName, map);
		}
		return mapCode;
	}


	/**
	 * 根据表ID查询表下所有字段的通用代码值
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param tableId
	 * @param param
	 * @return
	 * @throws Exception Map<String,Map<String,String>>
	 * @throws
	 */
	@Override
	public Map<String, Map<String, String>> getColumnLookupByTableId(String orgId, String deptId, String sysId, String tableId,Map<String, Object> param) throws Exception {
		Map<String, Map<String, String>> mapCode = new HashMap<String, Map<String, String>>();// 返回值
		// 获取公共字段信息
		StringBuffer sbSqlpub = new StringBuffer();
		sbSqlpub.append("SELECT CTC.*\n");
		sbSqlpub.append("  FROM CBB_TAB_COLUMNS CTC\n");
		sbSqlpub.append("  LEFT JOIN CBB_TABLES CT\n");
		sbSqlpub.append("    ON CT.ID = CTC.TABLE_ID\n");
		sbSqlpub.append(" WHERE CT.SYS_ID = '" + sysId + "'");
		sbSqlpub.append("   AND (CTC.COL_DROPDOWN_TYPE = '1' OR CTC.COL_DROPDOWN_TYPE = '2')");
		sbSqlpub.append("   AND CT.ID = '" + tableId + "'\n");
		List<Map<String, Object>> list = jdbcAvicit.queryForMap(sbSqlpub.toString(), null);
		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = list.get(i);
			String colId = String.valueOf(map.get("ID"));// 列ID
			String colName = String.valueOf(map.get("COL_NAME"));// 列英文名
			// 判断该字段是否存在通用代码
			StringBuffer sbSql = new StringBuffer();
			sbSql.append("WITH T1 AS\n");
			sbSql.append(" (SELECT CTCC.LOOKUP_NAME, CTCC.LOOKUP_CODE, CTCC.CODE_ORDER\n");
			sbSql.append("    FROM CBB_TAB_COL_CODE CTCC\n");
			sbSql.append("   WHERE CTCC.COLUMN_ID = '" + colId + "' AND CTCC.CODE_IS_VALID = 'Y'\n");
			sbSql.append("  UNION\n");
			sbSql.append("  SELECT CLV.LOOKUP_NAME, CLV.LOOKUP_CODE, CLV.CODE_ORDER\n");
			sbSql.append("    FROM CBB_TAB_COL_SYS_CODE CTCSC\n");
			sbSql.append("    LEFT JOIN CBB_LOOKUP_V CLV\n");
			sbSql.append("      ON CLV.ID = CTCSC.SYS_LOOKUP_ID\n");
			sbSql.append("   WHERE CTCSC.COLUMN_ID = '" + colId + "')\n");
			sbSql.append("SELECT T1.LOOKUP_NAME, T1.LOOKUP_CODE FROM T1 ORDER BY T1.CODE_ORDER");
			List<Object[]> colCodeList = hibernateDao.findBySQL(sbSql.toString());
			Map<String, String> remap = new LinkedHashMap<String, String>();
			map.put("", "---请选择---");
			for (int j = 0; j < colCodeList.size(); j++) {
				Object obj[] = colCodeList.get(j);
				String lookupName = String.valueOf(obj[0]);// 显示值
				String lookupCode = String.valueOf(obj[1]);// 真实值
				remap.put(lookupCode, lookupName);
			}
			mapCode.put(colName, remap);
		}
		return mapCode;
	}

	/**
	 * 根据表ID，获取列信息
	 * @author 张余
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param tableId
	 * @param Map
	 * 			showFlagJG 	1，系统字段
	 * 						2，可见
	 * 						3, 必著
	 *			showFlagYM
	 * 						1，查询字段
	 * 						2，列表显示
	 * 						3，详细显示
	 * @return
	 * @throws Exception
	 *             List<Map<String,Object>>
	 * @throws
	 */
	@Override
	public List<Map<String, Object>> getCbbTabColumnsByMap(String orgId, String deptId, String sysId, String tableId, Map<String, Object> map) throws Exception {
		sysId = sysId.toUpperCase(); // 将参数转换为大写
		List<Map<String, Object>> listFields = new ArrayList<Map<String, Object>>();
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT T.*\n");
		sbSql.append("  FROM CBB_TAB_COLUMNS T\n");
		sbSql.append(" WHERE T.SYS_ID = '" + sysId + "'\n");
		sbSql.append("   AND T.TABLE_ID = '" + tableId + "'\n");
		if (map.size() > 0) {
			if (null != map.get("showFlagJG") && !map.get("showFlagJG").equals("")) {
				int showFlagJG = Integer.parseInt(map.get("showFlagJG").toString());
				switch (showFlagJG) {
					case 1:
						sbSql.append("   AND T.COL_IS_SYS = 'Y'\n");
						break;
					case 2:
						sbSql.append("   AND T.COL_IS_DISPLAY = 'Y'\n");
						break;
					case 3:
						sbSql.append("   AND T.COL_IS_MUST = 'Y'\n");
						break;
					default:
						break;
				}
			}
			if (null != map.get("showFlagYM") && !map.get("showFlagYM").equals("")) {
				int showFlagYM = Integer.parseInt(map.get("showFlagYM").toString());
				switch (showFlagYM) {
					case 1:
						sbSql.append("   AND T.COL_IS_SEARCH = 'Y'\n");
						break;
					case 2:
						sbSql.append("   AND T.COL_IS_TAB_VISIBLE = 'Y'\n");
						break;
					case 3:
						sbSql.append("   AND T.COL_IS_DETAIL = 'Y'\n");
						break;
					default:
						break;
				}
			}

		}
		sbSql.append(" ORDER BY T.COL_ORDER,T.COL_NAME");
		listFields = jdbcAvicit.queryForMap(sbSql.toString(), null);
		// 查找节点著录定义配置信息，如果有配置信息，覆盖旧值返回

		return listFields;
	}

	/**
	 * 检查对应模版类型是否存在相同字段
	 * @param param
	 * @return
	 * @throws Exception String
	 * @throws
	 */
	@Override
	public String checkTemplateFieldsRepeat(Map<String, Object> param) throws Exception {
		String orgId = (String) param.get("ORG_ID");
		String sysId = (String) param.get("SYS_ID");
		String modelType = (String) param.get("MODEL_TYPE");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT * FROM (SELECT C.COL_NAME, COUNT(C.COL_NAME) COL_COUNT\n");
		sbSql.append("  FROM CBB_TEMPLET_FIELD C\n");
		sbSql.append(" WHERE C.TEMPLET_ID IN (\n");
		sbSql.append("       SELECT T.ID\n");
		sbSql.append("      FROM CBB_TEMPLET_INFO T\n");
		sbSql.append("     WHERE T.TEMP_TYPE = 'S'\n");
		sbSql.append("       AND T.SYS_ID = '" + sysId + "' or ((T.ORG_ID = 'ORG_ROOT' OR T.ORG_ID = '" + orgId + "')\n");
		sbSql.append("    AND T.TEMP_MODEL_TYPE = '" + modelType + "')\n");
		sbSql.append(" )\n");
		sbSql.append(" GROUP BY C.COL_NAME) T\n");
		sbSql.append(" WHERE T.COL_COUNT > 1");
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
		String result = "0";
		if (list.size() > 0) {
			StringBuffer sbSql1 = new StringBuffer();
			sbSql1.append("SELECT *\n");
			sbSql1.append("  FROM CBB_TEMPLET_INFO T\n");
			sbSql1.append(" WHERE T.ORG_ID = '" + orgId + "'\n");
			sbSql1.append("   AND T.TEMP_MODEL_TYPE = '1'\n");
			sbSql1.append("   AND T.ID IN (SELECT C.TEMPLET_ID\n");
			sbSql1.append("                  FROM CBB_TEMPLET_FIELD C\n");
			sbSql1.append("                 WHERE C.COL_NAME IN (\n");
			String colNames = "";
			for (int i = 0; i < list.size(); i++) {
				Map<String, Object> map = list.get(i);
				sbSql1.append("'" + map.get("COL_NAME") + "'");
				colNames += map.get("COL_NAME");
				if (i != list.size() - 1) {
					colNames += "、";
				}
			}
			sbSql1.append("))");
			List<Map<String, Object>> repeatList = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql1.toString());
			String tempString = "模版：";
			for (int i = 0; i < repeatList.size(); i++) {
				Map<String, Object> repeatMap = repeatList.get(i);
				tempString += repeatMap.get("TEMP_NAME");
				if (i != repeatList.size() - 1) {
					tempString += "、";
				}
			}
			result = tempString + "中的字段：" + colNames + "，在公共模版中已存在，请检查本组织的模板字段！";
		}
		return result;
	}
}
